When the main file is created from a membuffer, there is no file entry that can be retrieved. This uses "__GLOBAL_I_a" in that case which is what was always used before r208128.
Details
Diff Detail
Event Timeline
Is it possible to test this?
I think if the input comes from stdin, sys::path::filename() returns <stdin>, which then gets turned into _stdin_ by the isPreprocessingNumberBody() loop – maybe this should be <null> / _null_ instead of the old _a spelling? (I don't care too much about this part.)
Fixed minor nits, changed GLOBAL_I_a to _GLOBALsub_I__null_ and added a test. I'd appreciate if somebody who uses CMake to run the unittests could test this. I tried to modify the CMakeLists by pattern matching, but haven't actually tested this.
I patched this in and tried it with CMake, it mostly works (with the capital G mentioned below). I also checked that it runs as part of ninja check-clang. lgtm with comments addressed.
lib/CodeGen/CGDeclCXX.cpp | ||
---|---|---|
430 | Nit: I'd just do - SmallString<128> FileName(llvm::sys::path::filename( - SM.getFileEntryForID(SM.getMainFileID())->getName())); + SmallString<128> FileName; + if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) + FileName = llvm::sys::path::filename(MainFile->getName()); + else + FileName = "<null>"; and nothing else, then you don't duplicate the CreateGlobalInitOrDestructFunction call. | |
unittests/CodeGen/BufferSourceTest.cpp | ||
33 ↗ | (On Diff #12909) | const char TestProgram[] = |
42 ↗ | (On Diff #12909) | Does anything own this? I think this should be stack-allocated. (?) |
unittests/CodeGen/CMakeLists.txt | ||
16 ↗ | (On Diff #12909) | This has to be clangCodeGen (note capital G). Maybe it should be CodeGenTests for ConsistenCy. |
(I left a comment on this on phab a while ago, but I haven't received an
email for that yet. Not sure if phab's mailer is slow. The comment does
show up for me on the web interface.)