[PATCH] D50805: Don't warn on returning the address of a label

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 15 17:35:19 PDT 2018


rsmith added a comment.

There is no guarantee that you can use an address-of-label value from one function invocation in another invocation of the same function. GCC's documentation says it's the user's own problem to prevent inlining and cloning if the program requires an address-of-label extension to always produce the same value for multiple invocations of the function. It might make sense to suppress the warning in the case where the function is `__attribute__((noinline))`, though.



================
Comment at: clang/lib/Sema/SemaInit.cpp:6919-6920
         // expression.
         if (LK == LK_StmtExprResult)
           return false;
         Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
----------------
We should not be producing warnings on address-of-label cases for `LK_StmtExprResult`, similarly to what we do here for `DeclRefExpr`s. If we fixed that (which I think is just a bug I introduced while refactoring this code), we'd no longer reject the example from the Linux kernel.


https://reviews.llvm.org/D50805





More information about the cfe-commits mailing list