-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[clang] move -Wcast-function-type under -Wextra #77178
Changes from 1 commit
d147292
386ea16
d14a0dc
daa462a
eb8ad4f
b2c2569
3774838
f07fb78
1cccdb8
ec4c425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||
// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this diagnostic is not already well tested, adding all of these additional unit tests makes sense. But it looks like there's quite a number of existing tests in other files. I don't think we should add a new file just to check this diagnostics behavior via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of adding extra runs for both -Wcast-function-type and -Wextra or should the one for -Wcast-function-type be done in a different issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just remove the newly created clang/test/Sema/warn-extra-cast-function-type-strict.c. If you have cases that expose bugs in the implementation, that is distinctly a separate issue from adding this warning under -Wextra. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. sounds good I will do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. File removed, and a FIXME comment added for the existing test. |
||||||
|
||||||
|
||||||
int t(int array[static 12]); | ||||||
int u(int i); | ||||||
const int v(int i); /* expected-warning {{'const' type qualifier on return type has no effec}} */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't have to do it as the file is now not added. |
||||||
int x(long); | ||||||
|
||||||
typedef int (f1)(long); | ||||||
typedef int (f2)(void*); | ||||||
typedef int (f3)(); | ||||||
typedef void (f4)(); | ||||||
typedef void (f5)(void); | ||||||
typedef int (f6)(long, int); | ||||||
typedef int (f7)(long,...); | ||||||
typedef int (f8)(int *); | ||||||
typedef int (f9)(const int); | ||||||
typedef int (f10)(int); | ||||||
|
||||||
f1 *a; | ||||||
f2 *b; | ||||||
f3 *c; | ||||||
f4 *d; | ||||||
f5 *e; | ||||||
f6 *f; | ||||||
f7 *g; | ||||||
f8 *h; | ||||||
f9 *i; | ||||||
f10 *j; | ||||||
|
||||||
void foo(void) { | ||||||
a = (f1 *)x; | ||||||
b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */ | ||||||
c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */ | ||||||
d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function type}} */ | ||||||
e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */ | ||||||
f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */ | ||||||
g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */ | ||||||
h = (f8 *)t; | ||||||
i = (f9 *)u; | ||||||
j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On line 6 we issue a diagnostic that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, even I found this strange. Is there a place we can verify which is the correct behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope @AaronBallman can clarify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the diagnostic here is incorrect. C23 6.7.6.3p4: So the type of the function does not include the qualifiers on the return type, which means that We get this wrong: https://godbolt.org/z/xvh449xrd I think this is a more general problem with how we model the function type: https://godbolt.org/z/G3vxjW9dh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, create an issue? Comment out this test case and put a comment relating to the new issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to create an issue, we've already got one: #39494 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth it to add a FIXME comment above the test case and point to that issue, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So finally the things. I need to do: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds correct to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
} |
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.
As written, tests checks only default language mode for C (which is
gnu99
AFAIK). Maybe we want to check other modes as well?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.
add runs for -std=cNN for all remaining 5 of them? and also add extra test cases where conflicts arise?
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.
Yes, more
RUN
lines with different-std=
options, and potentially moreexpected
directives tailored for particular language mode. We have an example of this in C++ defect report tests: https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/drs/dr6xx.cppNote that I might be biased here, as someone who've spent a significant time with C++ defect report test suite.