7

I get the warning controlling expression is constant on assert statement like this:

assert(... && "error message");

Why this warning on this assert? How can I suppress this warning?

NVCC is the NVIDIA cuda compiler, I think it is based on LLVM. Why does it give this warning, when the same compiles fine with GCC or Visual C++ compilers?

3
  • Compiler should default to gcc on linux according to the NVCC2.0 reference. Commented Nov 11, 2009 at 3:38
  • And gcc (at least 3.4.4 and 4.3.2) doesn't give such warnings. Maybe try to verify the compiler via #ifdef __GNUC__ / __GNUG__ ? Commented Nov 11, 2009 at 4:05
  • I can't even reproduce the warning and i don't gcc has any flags for suppressing that warning. Weird. Commented Nov 12, 2009 at 0:25

5 Answers 5

3

A portable alternative (possibly wrapped in a macro) would be something like:

 {
     const bool error_message = true;
     assert([...] && error_message);
 }

To clear up what i meant:

#define myAssert(msg, exp) { const bool msg(true); assert(msg && (exp)); }
// usage:
myAssert(ouch, a && b);

... gives e.g.:

assertion "ouch && (a && b)" failed [...]

Sign up to request clarification or add additional context in comments.

Comments

3

I ran into this exact problem and finally found a way to disable warnings on the device. Here are the details...

To disable a specific warning, you need to use the -Xcudafe flag combined with a token listed on this page (http://www.ssl.berkeley.edu/~jimm/grizzly_docs/SSL/opt/intel/cc/9.0/lib/locale/en_US/mcpcom.msg). For example, to disable the "controlling expression is constant" warning, pass the following to NVCC:

-Xcudafe "--diag_suppress=boolean_controlling_expr_is_constant"

This worked for me! For other warnings, see the above link.

Comments

3

Add the following somewhere near the beginning of your code:

#pragma diag_suppress boolean_controlling_expr_is_constant

Note that this will suppress all compiler warnings for "controlling expression is constant", not just the warning associated with your assertions.

I sometimes get this warning when checking constants or properties that are defined (or can be derived) at compile time, so in my experience the warning has been generally benign and OK to ignore.

1 Comment

You can also turn the warning back on with #pragma diag_warning boolean_controlling_expr_is_constant. However, these pragmas cannot be in device code. They are also completely undocumented as far as the CUDA toolkit goes, so I would not be surprised if they one day stopped functioning...
0

If it is LLVM based, then you can use something like this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"

char b = 'df'; // no warning.

#pragma clang diagnostic pop

From Controlling Diagnostics via Pragmas.

Comments

0

Try #pragma warning.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.