Skip to content

core: redefine LOG macro to fix tautological compare error#6612

Closed
smlng wants to merge 1 commit intoRIOT-OS:masterfrom
smlng:pr/core/logging
Closed

core: redefine LOG macro to fix tautological compare error#6612
smlng wants to merge 1 commit intoRIOT-OS:masterfrom
smlng:pr/core/logging

Conversation

@smlng
Copy link
Copy Markdown
Member

@smlng smlng commented Feb 15, 2017

required by #6600

@smlng smlng added Area: core Area: RIOT kernel. Handle PRs marked with this with care! Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Feb 15, 2017
@smlng smlng self-assigned this Feb 15, 2017
@smlng smlng requested a review from jnohlgard February 15, 2017 13:37
@smlng
Copy link
Copy Markdown
Member Author

smlng commented Feb 15, 2017

mhm, okay need to this another way. I'll see to it

@smlng smlng removed the request for review from jnohlgard February 15, 2017 16:13
@smlng smlng requested a review from kaspar030 February 15, 2017 16:13
@smlng
Copy link
Copy Markdown
Member Author

smlng commented Feb 16, 2017

for clarification, the statement:

#define LOG(level, ...) if (level <= LOG_LEVEL) log_write(level, __VA_ARGS__)

led to a tautological compare error when using toolchain LLVM. I read they also added this to gcc 6.x.y, so this will likely hit more often in the future.

[edit]
for example when LOG_LEVEL=LOG_INFO and you use LOG_INFO("Foobar") it results in if (LOG_INFO <= LOG_INFO)
[/edit]

This PR resolves the issue ...

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 16, 2017
@jnohlgard
Copy link
Copy Markdown
Member

jnohlgard commented Feb 16, 2017 via email

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Feb 16, 2017

@gebart please note that the logging defined here, has nothing to do with logging done be ENABLE_DEBUG! This logging facility is enabled when you #include "log.h" into your code and set an appropriate LOG_LEVEL, default is LOG_INFO -- while the other is done by #include "debug.h".

@kaspar030
Copy link
Copy Markdown
Contributor

and set an appropriate LOG_LEVEL, default is LOG_INFO

If you don't, the log code will be kicked out by the preprocessor, which this log.h previously intentionally tried to not do.

Can this be fixed with pragmas?

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Feb 16, 2017

@kaspar030 please elaborate, I'm unsure what you mean?

In any case with whatever LOG_LEVEL, LOG_{ERROR|WARNING|INFO|DEBUG} will be defined as (void)(0).

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Feb 23, 2017

@kaspar030 ping!

@kaspar030
Copy link
Copy Markdown
Contributor

In any case with whatever LOG_LEVEL, LOG_{ERROR|WARNING|INFO|DEBUG} will be defined as (void)(0).

Exactly that is what the log module tries to avoid. Not used debug code will end up as

if (0 < 1) {
   ...
}

... which the compile correctly marks as always true.
The idea is that the optimizer just removes the code, after it has been syntax checked.

Historically, there were proper changes to code, which did not update the corresponding DEBUG statements. Enabling DEBUG would break the compile, but our CI would not spot those as per default we compile with ENABLE_DEBUG == 0.

The next time someone wanted to actually debug, a lot of time was lost repairing broken debug statements elsewhere in the file.

That's why this PR's solution is contrary to what the module tries to achieve.

It should be possible to disable the warning (which points to expected behavior), using compiler pragmas. Sth like push/tautological-compare//pop should do.

@kaspar030
Copy link
Copy Markdown
Contributor

Historically

Just realized that @gebart already explained this...

@kaspar030
Copy link
Copy Markdown
Contributor

@smlng Can you try if this patch solves the problem?

https://gist.github.com/kaspar030/621c5929cb8256b5e327180b67739efd

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Mar 14, 2017

closing, superseded by #6744

@smlng smlng closed this Mar 14, 2017
@smlng smlng deleted the pr/core/logging branch May 31, 2017 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants