question about clang warning

I’m forwarding this question about clang warnings for a friend:

When I compile the test file below (taken from a larger real program) clang raises the following warning unless gcc-compat is disabled:

clang_gcc_compat.c:17:13: warning: ‘break’ is bound to current loop, GCC binds
it to the enclosing loop [-Wgcc-compat]
} while(__m(1));
^
clang_gcc_compat.c:8:3: note: expanded from macro ‘__m’
break;
^
1 warning generated.
/usr/x86_64-cros-linux-gnu/usr/lib/…/lib64/Scrt1.o:function _start: error: undefined reference to ‘main’
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

In my understanding the break statement is clearly part of the switch construct and in this context there is a single loop, it is not clear why clang is referring to an enclosing loop. Could someone verify that this is correct and explain why?

Thanks!

The source code for clang_gcc_compat.c is below:

/* x86_64-cros-linux-gnu-clang tmp/clang_gcc_compat.c */

#define __m(x)
({
switch (x) {
case 1:
{
break;
}
}
42;
})

void f() {
for (;:wink: {
do {
} while(__m(1));
}
}

I'm not sure that it's correct but there exist similar test cases that
would suggest it's the intended behavior.

https://github.com/llvm-mirror/clang/blob/master/test/Analysis/dead-stores.c#L483

This review shows a motivating example for this warning (which does not
include nested loops): https://reviews.llvm.org/D2518

Not sure that’s equivalent/related - in this case the break is inside a switch and seems to pertain to that switch. Doesn’t look to me like it has anything to do with any loops.

My read on this is that it’s a false positive - probably “any break in a statement expression” triggers this, instead of it being a bit more selective about whether that break appears within some other breakable scope.

So…is this a bug or not? Should I file a new issue in buganizer?

My best guess is that it’s a bug, yes - though I’m hardly an expert here. Filing a bug seems like a fine idea. Maybe cc rtrieu in case he’s interested.