Quantcast

question about clang warning

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

question about clang warning

Brian Cain via cfe-dev

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 (;;) {
    do {
    } while(__m(1));
  }
}


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about clang warning

Brian Cain via cfe-dev

On Mon, Apr 10, 2017 at 6:20 PM, Caroline Tice via cfe-dev <[hidden email]> wrote:

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

 

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?


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


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



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about clang warning

Brian Cain via cfe-dev


On Mon, Apr 10, 2017 at 5:53 PM Brian Cain <[hidden email]> wrote:
On Mon, Apr 10, 2017 at 6:20 PM, Caroline Tice via cfe-dev <[hidden email]> wrote:

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

 

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?


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


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.
 


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



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about clang warning

Brian Cain via cfe-dev
So...is this a bug or not?  Should I file a new issue in buganizer?


-- Caroline
[hidden email]

On Mon, Apr 10, 2017 at 9:00 PM, David Blaikie <[hidden email]> wrote:


On Mon, Apr 10, 2017 at 5:53 PM Brian Cain <[hidden email]> wrote:
On Mon, Apr 10, 2017 at 6:20 PM, Caroline Tice via cfe-dev <[hidden email]> wrote:

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

 

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?


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


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.
 


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




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about clang warning

Brian Cain via cfe-dev
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.

On Wed, Apr 12, 2017 at 9:28 AM Caroline Tice <[hidden email]> wrote:
So...is this a bug or not?  Should I file a new issue in buganizer?


-- Caroline
[hidden email]

On Mon, Apr 10, 2017 at 9:00 PM, David Blaikie <[hidden email]> wrote:


On Mon, Apr 10, 2017 at 5:53 PM Brian Cain <[hidden email]> wrote:
On Mon, Apr 10, 2017 at 6:20 PM, Caroline Tice via cfe-dev <[hidden email]> wrote:

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

 

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?


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


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.
 


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




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...