From 297908da5ba2195d92ce05701c0fe6e0d5edb19a Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Tue, 4 Apr 2017 16:50:46 +0000 Subject: [PATCH] [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 llvm-svn: 299447 --- clang/lib/Sema/SemaDecl.cpp | 4 +++- clang/test/SemaOpenCL/types.cl | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaOpenCL/types.cl diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 80b2355..7659fba 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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 // in a system header, don't emit this for compatibility with GCC. 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()))) return; diff --git a/clang/test/SemaOpenCL/types.cl b/clang/test/SemaOpenCL/types.cl new file mode 100644 index 0000000..dc14800 --- /dev/null +++ b/clang/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; -- 2.7.4