浏览代码

[Bug 25404] Fix crash on typedef in OpenCL 2.0

Fixed the assertion due to absence of source location for
implicitly defined types (using addImplicitTypedef()).
During Sema checks the source location is being expected
and therefore an assertion is triggered.

The change is not specific to OpenCL. But it is particularly
common for OpenCL types to be declared implicitly in Clang
to support the mode without the standard header.

Differential Revision: https://reviews.llvm.org/D31397



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299447 91177308-0d34-0410-b5e6-96231b3b80d8
Anastasia Stulova 8 年之前
父节点
当前提交
fa3d6e13f6
共有 2 个文件被更改,包括 9 次插入1 次删除
  1. 3 1
      lib/Sema/SemaDecl.cpp
  2. 6 0
      test/SemaOpenCL/types.cl

+ 3 - 1
lib/Sema/SemaDecl.cpp

@@ -2154,7 +2154,9 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
   // -Wtypedef-redefinition.  If either the original or the redefinition is
   // -Wtypedef-redefinition.  If either the original or the redefinition is
   // in a system header, don't emit this for compatibility with GCC.
   // in a system header, don't emit this for compatibility with GCC.
   if (getDiagnostics().getSuppressSystemWarnings() &&
   if (getDiagnostics().getSuppressSystemWarnings() &&
-      (Context.getSourceManager().isInSystemHeader(Old->getLocation()) ||
+      // Some standard types are defined implicitly in Clang (e.g. OpenCL).
+      (Old->isImplicit() ||
+       Context.getSourceManager().isInSystemHeader(Old->getLocation()) ||
        Context.getSourceManager().isInSystemHeader(New->getLocation())))
        Context.getSourceManager().isInSystemHeader(New->getLocation())))
     return;
     return;
 
 

+ 6 - 0
test/SemaOpenCL/types.cl

@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+// Check redefinition of standard types
+typedef atomic_int atomic_flag;