Patch by Axel Naumann!
Diff Detail
Event Timeline
The test case could be shared from PR33688:
echo 'void* func(char* p) __attribute__((annotate("blah"))); void* func(char* p){return p;}' > HEADER.h clang++ -std=c++14 -x c++-header -o HEADER.h.pch HEADER.h chmod a-r HEADER.h echo 'char i; void* ptr = func(&i);' | clang++ -v -std=c++14 -Xclang -fno-validate-pch -include-pch HEADER.h.pch -c -Xclang -emit-llvm -o - -x c++ -
To be clear: emitting annotations will trigger the determination of PresumedLocs. As part of that (but not the first part, IIRC) SourceManager::getBufferName(() will be called which will trigger the fopen of the file, just to get its name. Another task of PresumedLoc is to determine the line number which triggers an fopen; @v.g.vassilev is looking into a possible solution for that one.
@v.g.vassilev will this also benefit from ContentCache::getBuffer improvements from D33275? I guess if getBuffer transparently handles pointing to right buffer we won't need this change?
This change is for cases where you have no buffer, because the file was never fopen()ed, because it's an ASTReader InputFile.
Looks like most of the users of this function are detecting whether we're in the builtins buffer. Perhaps we should have a dedicated method for that which uses something more principled than a string comparison against "<built-in>"?
lib/Basic/SourceManager.cpp | ||
---|---|---|
1485 | This repeats the FID -> SLocEntry lookup; if you manage to get a ContentCache above, perhaps call getBuffer(...)->getBufferIdentifier() on it directly? (If you can't get a content cache, this code path will also fail and will produce the name "<<<INVALID BUFFER>>>".) |
This repeats the FID -> SLocEntry lookup; if you manage to get a ContentCache above, perhaps call getBuffer(...)->getBufferIdentifier() on it directly?
(If you can't get a content cache, this code path will also fail and will produce the name "<<<INVALID BUFFER>>>".)