r286144 - When the ASTImporter imports a source location, it avoids importing macro
Sean Callanan via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 12:42:25 PST 2016
Author: spyffe
Date: Mon Nov 7 14:42:25 2016
New Revision: 286144
URL: http://llvm.org/viewvc/llvm-project?rev=286144&view=rev
Log:
When the ASTImporter imports a source location, it avoids importing macro
expansions by calling getSpellingLoc(). That's great in most cases, but for
macros defined in the '<built-in>' source file, the source file is invalid
and does not import correctly, causing an assertion failure (the assertion
is Invalid SLocOffset or bad function choice).
A more reliable way to avoid this is to use getFileLoc(), which does not
return built-in locations. This avoids the crash but still preserves valid
source locations.
I've added a testcase that covers the previously crashing scenario.
https://reviews.llvm.org/D26054
Added:
cfe/trunk/test/ASTMerge/Inputs/macro.modulemap
cfe/trunk/test/ASTMerge/Inputs/macro1.h
cfe/trunk/test/ASTMerge/Inputs/macro1.m
cfe/trunk/test/ASTMerge/Inputs/macro2.m
cfe/trunk/test/ASTMerge/macro.m
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=286144&r1=286143&r2=286144&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Nov 7 14:42:25 2016
@@ -6943,10 +6943,10 @@ SourceLocation ASTImporter::Import(Sourc
SourceManager &FromSM = FromContext.getSourceManager();
- // For now, map everything down to its spelling location, so that we
+ // For now, map everything down to its file location, so that we
// don't have to import macro expansions.
// FIXME: Import macro expansions!
- FromLoc = FromSM.getSpellingLoc(FromLoc);
+ FromLoc = FromSM.getFileLoc(FromLoc);
std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
SourceManager &ToSM = ToContext.getSourceManager();
FileID ToFileID = Import(Decomposed.first);
Added: cfe/trunk/test/ASTMerge/Inputs/macro.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro.modulemap?rev=286144&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/macro.modulemap (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro.modulemap Mon Nov 7 14:42:25 2016
@@ -0,0 +1,4 @@
+module macro1 [extern_c] {
+ header "macro1.h"
+ export *
+}
Added: cfe/trunk/test/ASTMerge/Inputs/macro1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro1.h?rev=286144&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/macro1.h (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro1.h Mon Nov 7 14:42:25 2016
@@ -0,0 +1,5 @@
+typedef void *VoidRef;
+
+void maybeNull(
+ int i,
+ __nullable VoidRef *__nullable);
Added: cfe/trunk/test/ASTMerge/Inputs/macro1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro1.m?rev=286144&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/macro1.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro1.m Mon Nov 7 14:42:25 2016
@@ -0,0 +1,5 @@
+ at import macro1;
+
+void foo() {
+ maybeNull(0, 0);
+}
Added: cfe/trunk/test/ASTMerge/Inputs/macro2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/macro2.m?rev=286144&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/macro2.m (added)
+++ cfe/trunk/test/ASTMerge/Inputs/macro2.m Mon Nov 7 14:42:25 2016
@@ -0,0 +1,5 @@
+void foo();
+
+void bar() {
+ foo();
+}
Added: cfe/trunk/test/ASTMerge/macro.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/macro.m?rev=286144&view=auto
==============================================================================
--- cfe/trunk/test/ASTMerge/macro.m (added)
+++ cfe/trunk/test/ASTMerge/macro.m Mon Nov 7 14:42:25 2016
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/cache
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.1.ast %S/Inputs/macro1.m
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fmodule-map-file=%S/Inputs/macro.modulemap -I%S/Inputs -emit-pch -o %t.2.ast %S/Inputs/macro2.m
+// RUN: %clang_cc1 -fmodules -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
More information about the cfe-commits
mailing list