[PATCH] D15804: Fix isBeforeInTranslationUnit to not abort on macros defined in cmdline.
Yury Gribov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 29 02:26:51 PST 2015
ygribov created this revision.
ygribov added reviewers: doug.gregor, joerg.
ygribov added subscribers: llvm-commits, a.sidorin.
ygribov set the repository for this revision to rL LLVM.
This patch fixes assert "Unsortable locations found" when calling
PathDiagnosticLocation(SM.getSpellingLoc(E->getLocStart()), SM);
on an expression which comes from cmdline (i.e. macro defined with -D). Such expressions come from a special scratch buffer and thus trigger assert when passed to isBeforeInTranslationUnit.
Unfortunately this only reproduces on a local branch so I can not provide a minimal testcase. I hope the fix is self-evident though.
Repository:
rL LLVM
http://reviews.llvm.org/D15804
Files:
lib/Basic/SourceManager.cpp
Index: lib/Basic/SourceManager.cpp
===================================================================
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -2089,27 +2089,35 @@
// Clear the lookup cache, it depends on a common location.
IsBeforeInTUCache.clear();
- llvm::MemoryBuffer *LBuf = getBuffer(LOffs.first);
- llvm::MemoryBuffer *RBuf = getBuffer(ROffs.first);
- bool LIsBuiltins = strcmp("<built-in>", LBuf->getBufferIdentifier()) == 0;
- bool RIsBuiltins = strcmp("<built-in>", RBuf->getBufferIdentifier()) == 0;
+ const char *LB = getBuffer(LOffs.first)->getBufferIdentifier();
+ const char *RB = getBuffer(ROffs.first)->getBufferIdentifier();
+ bool LIsBuiltins = strcmp("<built-in>", LB) == 0;
+ bool RIsBuiltins = strcmp("<built-in>", RB) == 0;
// Sort built-in before non-built-in.
if (LIsBuiltins || RIsBuiltins) {
if (LIsBuiltins != RIsBuiltins)
return LIsBuiltins;
// Both are in built-in buffers, but from different files. We just claim that
// lower IDs come first.
return LOffs.first < ROffs.first;
}
- bool LIsAsm = strcmp("<inline asm>", LBuf->getBufferIdentifier()) == 0;
- bool RIsAsm = strcmp("<inline asm>", RBuf->getBufferIdentifier()) == 0;
+ bool LIsAsm = strcmp("<inline asm>", LB) == 0;
+ bool RIsAsm = strcmp("<inline asm>", RB) == 0;
// Sort assembler after built-ins, but before the rest.
if (LIsAsm || RIsAsm) {
if (LIsAsm != RIsAsm)
return RIsAsm;
assert(LOffs.first == ROffs.first);
return false;
}
+ bool LIsScratch = strcmp("<scratch space>", LB) == 0;
+ bool RIsScratch = strcmp("<scratch space>", RB) == 0;
+ // Sort scratch after inline asm, but before the rest.
+ if (LIsScratch || RIsScratch) {
+ if (LIsScratch != RIsScratch)
+ return LIsScratch;
+ return LOffs.second < ROffs.second;
+ }
llvm_unreachable("Unsortable locations found");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15804.43724.patch
Type: text/x-patch
Size: 1909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151229/be436e9d/attachment.bin>
More information about the llvm-commits
mailing list