Fixed by adding isImplicit() check.
Please make review of the patch.
Details
- Reviewers
majnemer arsenm asl pxli168 • ichesnokov
Diff Detail
Event Timeline
SemaDecl.cpp | ||
---|---|---|
2038 ↗ | (On Diff #45498) | Added isImplicit() check, because implicit TypeDecl::getLocation() |
lib/Sema/SemaDecl.cpp | ||
---|---|---|
2039 | It is not tab, it is triple space |
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
3 | Not necessary. Removed. |
BugZilla page: https://llvm.org/bugs/show_bug.cgi?id=25404
Please review and submit this bug.
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
3 | -main-file-name is not necessary. Removed. |
Why isn't this logic buried in GetArgumentVector so that other tools may
take advantage of it?
majnemer: Why isn't this logic buried in GetArgumentVector so that other tools may take advantage of it?
Sorry, I do not understand what you say.
I looked into GetArgumentVector and this function is dummy now in both Unix and Windows, and it does not look like correct place to implement this fix.
Could you please clarify what the change do you propose?
This fix is global, not only for OpenCL. The patch is .cl because initial bug report is for OpenCL.
What can I do is generalizing the bug by adding patch in .c.
lib/Sema/SemaDecl.cpp | ||
---|---|---|
2038 | Braces are not needed. | |
test/SemaOpenCL/implicit-typedef.cl | ||
2 | "-cc1" is not needed. I have a feeling most of the things are not needed here. Generally doesn't seem to follow the style. Could you please check other tests as an example. Let's say test/SemaOpenCL/extern.cl. | |
3 | So now we just silently allow to redefine a builtin OpenCL type. Wondering if giving a warning would be a better option? |
Warnings added to the case. Turned off by default:
Original bahavior:
" If we have a redefinition of a typedef in C, emit a warning. This warning
is normally mapped to an error, but can be controlled with
-Wtypedef-redefinition. If either the original or the redefinition is
in a system header, don't emit this for compatibility with GCC.
"
The similar is applied to implicit/builtin typedefs.
It needs to define -Wsystem-headers to see the warning.
lib/Sema/SemaDecl.cpp | ||
---|---|---|
2039 | redifinition -> redefinition | |
test/SemaOpenCL/implicit-typedef.cl | ||
2 | Could we also add a run line without -Wsystem-headers. You can pass -D and use #ifdef for checking the error conditionally in this test. | |
3 | atomic_flag is a part of OpenCL not C11 here. I think it would be nicer to change this error to use select and pass either C11 or OpenCL. |
Test case enriched to check typedef redefinition without warnings.
Minor fix of comment.
lib/Sema/SemaDecl.cpp | ||
---|---|---|
2039 | Fixed. | |
test/SemaOpenCL/implicit-typedef.cl | ||
3 | Done. | |
4 | Are you mean another text of warning? Notice that actual patch will work not only in OpenCL, but any language. If builtin functions present, it will prevent the crash. The single message "redefinition of typedef 'atomic_flag' is a C11 feature" is default for all targets. |
Notice that redefinition of typedef defined at system header will show the same message.
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
4 | No, you can use select{OpenCL|C11} or you can pass 'OpenCL' or 'C11' as a string to the diagnostic as an argument. You can take a look at err_opencl_unknown_type_specifier as an example, that uses both approaches. LangOpts.OpenCL will help you to detect the language mode for selecting/passing the right string. |
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
4 | I can't find anything like select{} in my local copy (there's LLVM and Clang).
Currently it checks both Microsoft and Itanium manglers on all platforms, with one test case. Excuse me, could you please explain more? |
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
4 | Example of select is in include/clang/Basic/DiagnosticSemaKinds.td line 7707 at revision 259811. def err_opencl_unknown_type_specifier : Error< "OpenCL does not support the '%0' %select{type qualifier|storage class specifier}1">; Regarding the OpenCL check you can call getLangOpts().OpenCL to check if you compile for OpenCL (see examples in lib/Sema/SemaDecl.cpp). bool IsOpenCL = getLangOpts().OpenCL ? 1: 0; Diag(New->getLocation(), diag::ext_redefinition_of_typedef) << New->getDeclName() << IsOpenCL; |
Another warning text implemented for OpenCL.
Like: redefinition of OpenCL builtin typedef 'atomic_flag'
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
4 | Thank you, Anastasia! |
test/SemaOpenCL/implicit-typedef.cl | ||
---|---|---|
1 | do you need -pedantic here? |
I just closed the bug because it's no longer failing on the master branch. So I don't think this is needed.
Braces are not needed.