Index: lib/Basic/SourceManager.cpp =================================================================== --- lib/Basic/SourceManager.cpp +++ lib/Basic/SourceManager.cpp @@ -2089,10 +2089,10 @@ // 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("", LBuf->getBufferIdentifier()) == 0; - bool RIsBuiltins = strcmp("", RBuf->getBufferIdentifier()) == 0; + const char *LB = getBuffer(LOffs.first)->getBufferIdentifier(); + const char *RB = getBuffer(ROffs.first)->getBufferIdentifier(); + bool LIsBuiltins = strcmp("", LB) == 0; + bool RIsBuiltins = strcmp("", RB) == 0; // Sort built-in before non-built-in. if (LIsBuiltins || RIsBuiltins) { if (LIsBuiltins != RIsBuiltins) @@ -2101,8 +2101,8 @@ // lower IDs come first. return LOffs.first < ROffs.first; } - bool LIsAsm = strcmp("", LBuf->getBufferIdentifier()) == 0; - bool RIsAsm = strcmp("", RBuf->getBufferIdentifier()) == 0; + bool LIsAsm = strcmp("", LB) == 0; + bool RIsAsm = strcmp("", RB) == 0; // Sort assembler after built-ins, but before the rest. if (LIsAsm || RIsAsm) { if (LIsAsm != RIsAsm) @@ -2110,6 +2110,14 @@ assert(LOffs.first == ROffs.first); return false; } + bool LIsScratch = strcmp("", LB) == 0; + bool RIsScratch = strcmp("", 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"); }