ichesnokov removed rL LLVM as the repository for this revision.
ichesnokov updated this revision to Diff 46634.
ichesnokov added a comment.
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.
http://reviews.llvm.org/D16351
Files:
lib/Sema/SemaDecl.cpp
test/SemaOpenCL/implicit-typedef.cl
Index: test/SemaOpenCL/implicit-typedef.cl
===================================================================
--- test/SemaOpenCL/implicit-typedef.cl
+++ test/SemaOpenCL/implicit-typedef.cl
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
-Wsystem-headers
+typedef atomic_int atomic_flag; // expected-warning {{redefinition of typedef
'atomic_flag' is a C11 feature}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2033,6 +2033,22 @@
if (getLangOpts().Modules || getLangOpts().C11)
return;
+ // Added isImplicit() check, because implicit TypeDecl::getLocation()
+ // returns 0. The're many implicit typedefs in OpenCL, e.g. atomic_flag.
+ if (Old->isImplicit() || New->isImplicit()) {
+ // Since we don't emit system header warnings for compatibility with GCC,
+ // don't do this for implicit type redifinition warnings the same way.
+ if (!getDiagnostics().getSuppressSystemWarnings()) {
+ if (New->getLocation().isValid()) {
+ Diag(New->getLocation(), diag::ext_redefinition_of_typedef)
+ << New->getDeclName();
+ if (Old->getLocation().isValid())
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ }
+ }
+ return;
+ }
+
// 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
Index: test/SemaOpenCL/implicit-typedef.cl
===================================================================
--- test/SemaOpenCL/implicit-typedef.cl
+++ test/SemaOpenCL/implicit-typedef.cl
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -Wsystem-headers
+typedef atomic_int atomic_flag; // expected-warning {{redefinition of typedef 'atomic_flag' is a C11 feature}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2033,6 +2033,22 @@
if (getLangOpts().Modules || getLangOpts().C11)
return;
+ // Added isImplicit() check, because implicit TypeDecl::getLocation()
+ // returns 0. The're many implicit typedefs in OpenCL, e.g. atomic_flag.
+ if (Old->isImplicit() || New->isImplicit()) {
+ // Since we don't emit system header warnings for compatibility with GCC,
+ // don't do this for implicit type redifinition warnings the same way.
+ if (!getDiagnostics().getSuppressSystemWarnings()) {
+ if (New->getLocation().isValid()) {
+ Diag(New->getLocation(), diag::ext_redefinition_of_typedef)
+ << New->getDeclName();
+ if (Old->getLocation().isValid())
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ }
+ }
+ return;
+ }
+
// 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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits