This is an archive of the discontinued LLVM Phabricator instance.

Do not read the file to determine its name.
Needs ReviewPublic

Authored by v.g.vassilev on Jul 4 2017, 7:57 AM.

Details

Reviewers
rsmith
bruno
Summary

Patch by Axel Naumann!

Diff Detail

Event Timeline

v.g.vassilev created this revision.Jul 4 2017, 7:57 AM

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++ -
karies added a comment.Jul 5 2017, 2:34 AM

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.

bruno edited edge metadata.Jul 6 2017, 3:14 PM

@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?

karies added a comment.Jul 7 2017, 8:37 AM

@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.

rsmith edited edge metadata.Jul 7 2017, 1:32 PM

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>>>".)

bruno resigned from this revision.Nov 9 2020, 12:28 PM