-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
fix bug that undefined internal is a warning only for -pedantic-errors #98016
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Constantin Kronbichler (ccrownhill) ChangesThis fixes issue #39558 which mentions the problem when compiling the following code with static void f();
int main()
{
f;
} Clang only outputs an
this should be illegal and hence an error. I fixed this by changing the warning type from Full diff: https://github.com/llvm/llvm-project/pull/98016.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..ae3dbedd01693 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note<
"because field %2 is of %select{reference|const-qualified}4 type %3">;
// These should be errors.
-def warn_undefined_internal : Warning<
+def warn_undefined_internal : ExtWarn<
"%select{function|variable}0 %q1 has internal linkage but is not defined">,
InGroup<DiagGroup<"undefined-internal">>;
def err_undefined_internal_type : Error<
diff --git a/clang/test/Sema/undefined_internal.c b/clang/test/Sema/undefined_internal.c
new file mode 100644
index 0000000000000..1b6c3a4b76e05
--- /dev/null
+++ b/clang/test/Sema/undefined_internal.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-error {{function 'f' has internal linkage but is not defined}}
+
+int main(void)
+{
+ f;
+ // expected-note@-1 {{used here}}
+ // expected-warning@-2 {{expression result unused}}
+}
+
|
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.
Thanks for the fix!
The changes LGTM, but you should also add a release note about this (in clang/docs/ReleaseNotes.rst
, probably in the ‘Improvements to Clang’s Diagnostics’ section).
Ok I just added a commit with the addition to |
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.
Thank you for working on this! C23 changed the normative wording here somewhat, so I think we should add additional test coverage. Specifically:
Moreover, if an identifier declared with internal linkage is used in an expression
there shall be exactly one external definition for the identifier in the translation unit, unless it is:
— part of the operand of a sizeof operator whose result is an integer constant;
— part of the operand of an alignof operator whose result is an integer constant;
— part of the controlling expression of a generic selection;
— part of the expression in a generic association that is not the result expression of its generic
selection;
— or, part of the operand of any typeof operator whose result is not a variably modified type.
How about adding those bullets as test cases to make sure we don't diagnose them?
That sounds good. I will have a look at that later today. |
I added three more tests covering these points: I did not see how to add tests for the following since they require just a type which I thought to be possible to achieve Is there a way to test undefined internals for these cases? |
What I had in mind for those was:
|
Ah I see. Thank you for the suggestions! For the other two I had something similar but that still misses this point: Also, I was thinking that it would be best to group all tests into one file since they all test just one feature. |
Since one error message will occlude others I had to split the files as I did in the latest commit. |
Given: |
Oh that makes sense so
should be ok since it is not in the result expression? |
Sorry, my mistake. This doesn't work for
the |
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 think the test cases should all be combined into a single file -- we don't stop issuing diagnostics after the first one, so it should be fine to put them all together into one file.
Correct, that's a good test case to add! Similarly, it would be good to add one like:
to show that it is diagnosed because it's used in the result expression. |
Thank you very much for all the feedback:) I'll combine them into a file now. |
The only problem is that currently, the behavior of Clang is incorrect for the case
because it gives an error even though it should not. |
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
Co-authored-by: Aaron Ballman <[email protected]>
If you look into it and it seems challenging to resolve, I think we can leave a FIXME comment next to the test case saying "this code is incorrectly rejected and should be accepted", file an issue in GitHub about it, and then land these changes because they're definitely an incremental improvement over what we have today. |
Ok, I'll have a look after adding the above test cases. And also since the |
Yeah, go ahead and add the test, and add whatever
I'd probably spell it |
Ok, that's done with the FIXME comment for now. |
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.
LGTM!
I filed #98504 to track the remaining issue. |
@ccrownhill Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/2080 Here is the relevant piece of the build log for the reference:
|
…ic-errors (#98016)" This reverts commit e16882f. Broken bots: https://lab.llvm.org/buildbot/#/builders/144/builds/2080
I've reverted the changes in 9f283bf because of the bot breakage. Oddly, I am seeing a different failure on Windows locally:
so something has gone amiss... |
Okay, the Windows issue seems to have gone away with a full rebuild, which makes way more sense to me. :-) So I think it's just the |
I think adding |
I've relanded the changes with a fix here in commit 0171e23, hopefully that sticks! |
Yup, that resolved the issue: https://lab.llvm.org/buildbot/#/builders/144/builds/2082 -- not certain why that builder has a different default value for |
This bot targets the PS4 which has kept an older version of the standard as the default for compatibility reasons. |
Ahhhhh! I remembered that the PS used older versions of the standard, but I didn't realize that was this bot. "SIE" -- Sony Interactive Entertainment... now I get it. Thank you! :-) |
Thank you very much for fixing that:) |
Happy to help, thank you for your contribution! |
llvm#98016) This fixes issue llvm#39558 which mentions the problem when compiling the following code with `-pedantic-errors` flag (it also mentions `-Wall -Wextra` but those shouldn't change the output, which is also the case in GCC): ```c static void f(); int main() { f; } ``` Clang only outputs an `undefined-internal` warning on the first line, but according to 6.9/3 ``` "... Moreover, if an identifier declared with internal linkage is used in an expression (other than as a part of the operand of a sizeof or _Alignof operator whose result is an integer constant), there shall be exactly one external definition for the identifier in the translation unit." ``` this should be illegal and hence an error. I fixed this by changing the warning type from `Warning` to `ExtWarn` and by adding a suitable test.
…ic-errors (llvm#98016)" This reverts commit e16882f. Broken bots: https://lab.llvm.org/buildbot/#/builders/144/builds/2080
This fixes issue #39558 which mentions the problem when compiling the following code with
-pedantic-errors
flag (it also mentions-Wall -Wextra
but those shouldn't change the output, which is also the case in GCC):Clang only outputs an
undefined-internal
warning on the first line, but according to 6.9/3this should be illegal and hence an error.
I fixed this by changing the warning type from
Warning
toExtWarn
and by adding a suitable test.