[PATCH] D16351: [FIX] Bug 25404 - Crash on typedef in OpenCL 2.0
Igor Chesnokov via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 7 09:18:51 PST 2016
ichesnokov updated this revision to Diff 47137.
ichesnokov added a comment.
Another warning text implemented for OpenCL.
Like: redefinition of OpenCL builtin typedef 'atomic_flag'
http://reviews.llvm.org/D16351
Files:
include/clang/Basic/DiagnosticSemaKinds.td
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,8 @@
+// RUN: %clang_cc1 %s -DTEST_WARNINGS -cl-std=CL2.0 -verify -pedantic -fsyntax-only -Wsystem-headers
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -fsyntax-only
+
+#if defined(TEST_WARNINGS)
+typedef atomic_int atomic_flag; // expected-warning {{redefinition of OpenCL builtin typedef 'atomic_flag'}}
+#else
+typedef atomic_int atomic_flag;
+#endif
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2036,6 +2036,27 @@
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 redefinition warnings the same way.
+ if (!getDiagnostics().getSuppressSystemWarnings()) {
+ if (New->getLocation().isValid()) {
+ if (getLangOpts().OpenCL) {
+ Diag(New->getLocation(), diag::warn_opencl_redefinition_of_typedef)
+ << New->getDeclName();
+ } else {
+ 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: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7692,6 +7692,8 @@
" in the declaration statement in the program scope">;
def err_opencl_implicit_vector_conversion : Error<
"implicit conversions between vector types (%0 and %1) are not permitted">;
+def warn_opencl_redefinition_of_typedef : Warning<
+ "redefinition of OpenCL builtin typedef %0">;
// OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
def err_opencl_builtin_pipe_first_arg : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16351.47137.patch
Type: text/x-patch
Size: 2533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160207/7d4948e4/attachment.bin>
More information about the cfe-commits
mailing list