-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Use ExtWarn for static local variable in extern inline function (fixes #39524) #166332
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
Open
Susikrishna
wants to merge
9
commits into
llvm:main
Choose a base branch
from
Susikrishna:fix-inline-static-extwarn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16414b9
[Clang] Use ExtWarn for static local variable in extern inline functi…
Susikrishna 456e2df
Merge branch 'main' into fix-inline-static-extwarn
Susikrishna ee314e1
Update clang/test/Sema/inline-static-var.c
Susikrishna b4abe8e
Update release notes and diagnostics for static local variables in ex…
Susikrishna d5431b8
Update clang/docs/ReleaseNotes.rst
Susikrishna 544b1ba
Update release note to refer to `inline` functions instead of `extern…
Susikrishna 44c4a48
Update clang/test/Sema/inline-static-var.c
Susikrishna af464fe
Merge branch 'main' into fix-inline-static-extwarn
Susikrishna 28b67f8
[Clang][Sema] Use Linux triple for inline-static-var.c to ensure cons…
Susikrishna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c11 -pedantic-errors -verify %s | ||
|
|
||
| inline void f(void) { // expected-note {{use 'static' to give inline function 'f' internal linkage}} | ||
| static int x; // expected-error {{non-constant static local variable in inline function may be different in different files}} | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think the test should have a triple; I would expect this diagnostic to be target-agnostic based on the code which emits the diagnostic. Can you hook up a debugger to see why the diagnostic was being silenced on Windows targets in the first place?
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.
Hi @AaronBallman,
Thanks for the review. I checked it, and it seems the diagnostic is intentionally target-dependent. I'd be grateful if you could sanity-check my reasoning below:
My understanding is that this all comes down to the behavior of isFunctionDefinitionDiscarded() in this block in SemaDecl.cpp:
On Windows (MSVC): Clang emulates the MSVC model, where inline acts like C++ and is the "real" external definition. The linker just merges all the identical copies. Because this definition is not "discardable," isFunctionDefinitionDiscarded() returns false, and our diagnostic (correctly) doesn't fire.
On Linux (GNU): Clang uses the C99 model, where inline is just a "discardable copy" that's separate from the "real" definition. Because this definition is "discardable," isFunctionDefinitionDiscarded() returns true, which is what triggers our ExtWarn.
So, it seems the CI failed on Windows simply because, under MSVC's rules, this code isn't an error.
If that sounds right, then adding the -triple x86_64-pc-linux-gnu to the test file feels like the correct solution, as it forces the test to check against the GNU/C99 semantics we're actually trying to fix.
I'm not completely sure if this is the standard way to handle a target-specific test, though. Please let me know if there's a better approach!