-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Emit bad shift warnings #70307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
894d650
to
c9b85c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch summary doesn't really explain why the changes are needed. Can you explain what problem you're solving (perhaps link to an issue if this is fixing one that was reported by someone)?
Main goal of this patch is to enable diagnosing and emitting warnings related to shift operator that are already found by GCC. Original proposal fix and comments were posted on Pharbricator (link). This patch continues that patch. |
c9b85c8
to
c89be5f
Compare
Ping @AaronBallman |
There are two questions above about removing a diagnostic that you haven't answered yet |
c89be5f
to
c9ef2f2
Compare
c9ef2f2
to
17fb77d
Compare
0ed3473
to
69c6fc0
Compare
9e4309a
to
a66ca21
Compare
a66ca21
to
a46a2c2
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/1622 Here is the relevant piece of the build log for the reference:
|
FYI this is causing breakages in chrome - the android NDK has an enum element set equal to code in question is here: https://android.googlesource.com/platform/frameworks/native/+/master/libs/nativewindow/include/android/hardware_buffer.h#329 The android NDK code is wrong, but this no longer compiles (even with |
Well that's unfortunate! Thank you for letting us know. @alanzhao1 do you think it's reasonable for the workaround to only apply to code in system headers, or does the NDK get included as regular headers generally? Do you need us to revert the changes while we resolve this? @budimirarandjelovicsyrmia, can you please add a workaround so that the NDK code can continue to compile? |
I will investigate this. |
Having it only apply to system headers should be OK - in our case, chrome imports these headers as part of a
If you can revert while working on a solution, that would be helpful.
FYI I noticed that gcc can compile this with |
Diagnose bad shifts and emit warnings
This started to cause
to emit a warning, and I'm not sure that's intentional? |
That is intentional; |
Thanks for confirming. From the commit message and the changes to |
> desktop/unx/source/start.c:788:23: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] > 788 | char resp[strlen("InternalIPC::SendArguments") + 1]; > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ since <llvm/llvm-project@e4163c0> "[clang] Emit bad shift warnings (#70307)" (and see the comments starting at <llvm/llvm-project#70307 (comment)> "[clang] Emit bad shift warnings" for how this new warning is indeed intentional) Change-Id: Ie439a0f5f6f3b256fa82ec3a05fdc5fb3b840715 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170510 Reviewed-by: Stephan Bergmann <[email protected]> Tested-by: Jenkins
Just to confirm: is this the intentional outcome of this patch?
Though technically, it's UB before C++20, the diagnostic - "expression is not an integral constant expression" - doesn't sound helpful (how is it not constant or not integral?). And what's worse, is that it's an error rather than a warning that can be disabled. |
Before C++20, left shift of -1 does not produce a mathematical result that's within the range of representable values for the result type, so it's undefined behavior, and therefore not a core constant expression, and therefore invalid as the initializer for an enumeration constant. So I believe the behavior is expected and correct; you can see the UB diagnostic in other contexts: https://gcc.godbolt.org/z/bqj6xhzzr and GCC agrees with Clang in the enumeration case: https://gcc.godbolt.org/z/qjKzeaYTz
It has integral constants but it's not an integral constant expression as far as the language is concerned. The note tells you why it's not a valid integral constant expression. As for warning vs error; the standard makes the code ill-formed and we treat that as an error generally speaking. If you can't enable C++20 mode, you can still get the same value in C++17 and earlier with well-formed code: https://gcc.godbolt.org/z/3ra83joqs |
I see. Thanks for the explanation and for the suggestion on how to fix that. Actually, the only instance I've seen, had already been fixed upstream (https://hg.openjdk.org/jdk/jdk/rev/71495d579a65), so the impact of this compiler behavior change is quite low in my part of the universe. |
Now there's a different and more subtle side-effect of this patch: https://gcc.godbolt.org/z/YP3EfGern The invalid expression |
Huh, I don't think that's an intentional change in this patch, good catch! Adding |
I think the issue is the usage of "Info.EvalStatus.Diag" to determine whether we consider the expression an ICE; that's going to lead to unpredictable results, and it's not how we handle things anywhere else. Not sure what the goal of that change is. Separately, Sema::AddInitializerToDecl should probably print diagnostics when it checks for an ICE, instead of just emitting the generic diag::err_in_class_initializer_non_constant/diag::ext_in_class_initializer_non_constant. Any maybe we should consider enabling ext_in_class_initializer_non_constant by default. |
We (Chrome) no longer need a revert - we patched the NDK locally. |
Posted #99579. |
Thank you for letting us know! |
This patch removes trailing whitespace from `SemaExpr.cpp` added by #70307
Patching the NDK is not a solution that is nice everywhere, though. And the new warning is an error that can't be disabled. |
FWIW, we addressed this issue and backported the fix in #100452 -- are you seeing issues with the latest release candidate? |
#100452 only fixed the "ignoring the in-class initializer of the static data member" issue. I don't think we did anything to allow downgrading overflow errors to warnings. |
I don't know about the latest release candidate, but trunk still has the problem. |
#102390 "fixes" the Android NDK issue. |
Diagnose bad shifts and emit warnings