Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Statement expr inside of __assume incorrectly considered to have side-effects

nemequ
New Contributor I
973 Views

I'm getting a ton of invalid warnings from ICC about an __assume with side effects.  It turns out the "problem" is that I'm using a statement expr (which has no side effects).  Here is a reduced test case:

#include <stdint.h>

void foo(int *bar) {
  __assume((
	    ((uintptr_t) bar)
	    % 16) == 0);

  __assume((
	    (__extension__ ({ (uintptr_t) bar; }))
	    % 16) == 0);
}

Which triggers:

aa.c(8): warning #2261: __assume expression with side effects discarded
    __assume((
             ^

I've already tweaked my code to get rid of the statement expr, so no need to think of work-arounds on my behalf.  I just wanted to report the issue.

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
973 Views

I see two potential issues:

1) the extension contains a braced group
2) more importantly, bar is followed by a statement terminator ;, which means %16 is without a lhs operand

Jim Dempsey

 

0 Kudos
Viet_H_Intel
Moderator
973 Views

GNU also emits a warning

$ gcc t.c -c
t.c: In function ‘foo’:
t.c:4:3: warning: implicit declaration of function ‘__assume’ [-Wimplicit-function-declaration]
   __assume((
   ^~~~~~~~
 

0 Kudos
nemequ
New Contributor I
973 Views

Sorry about the delayed response.

jimdempseyatthecove (Blackbelt) wrote:

I see two potential issues:

1) the extension contains a braced group
2) more importantly, bar is followed by a statement terminator ;, which means %16 is without a lhs operand

That's not a braced group, it's a statement expr.  It's an extension available in gcc-2.95+ as well as clang, icc back to at least version 9, PGI, Oracle Developer Studio 5.12+, XL C/C++ 11+, Cray since at least 8.1, tinycc 0.9.26+, armcc since at least 4.1,  The only compilers I know don't support statement exprs are MSVC, Pelles, Digital Mars C, and I *think* IAR but I'd have to check on that.

It's basically a way of putting multiple statements inside of an expressions which is very useful for macros.

Viet Hoang (Intel) wrote:

GNU also emits a warning

$ gcc t.c -c
t.c: In function ‘foo’:
t.c:4:3: warning: implicit declaration of function ‘__assume’ [-Wimplicit-function-declaration]
   __assume((
   ^~~~~~~~

Yes, GCC doesn't support __assume.  ICC does, I believe as part of its efforts towards MSVC compatibility.  The closest thing in GCC would be something like `#define __asume(expr) ((expr) ? ((void) 0) : __builtin_unreachable())`.  Recent versions of clang do support a __builtin_assume, here is quick example on Compiler Explorer: https://godbolt.org/z/4yC8gR.

0 Kudos
Viet_H_Intel
Moderator
973 Views

You can also suppress the warning via -wd2261. Let's us close this case. 

0 Kudos
Reply