diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2020-04-22 16:37:27 +0200 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2020-04-22 21:01:52 +0200 |
commit | 411a254af3ff5dd05e6c522cc7bccdf043967070 (patch) | |
tree | 3f28072a7932a2a48c4e9462a9be964967cdd6a6 /clang/unittests/Basic/SourceManagerTest.cpp | |
parent | 7d1ee639cb9efea364bec90afe4d1161ec624a7f (diff) | |
download | llvm-411a254af3ff5dd05e6c522cc7bccdf043967070.zip llvm-411a254af3ff5dd05e6c522cc7bccdf043967070.tar.gz llvm-411a254af3ff5dd05e6c522cc7bccdf043967070.tar.bz2 |
[clang] Make sure argument expansion locations are correct in presence of predefined buffer
Summary:
Macro argument expansion logic relies on skipping file IDs that created
as a result of an include. Unfortunately it fails to do that for
predefined buffer since it doesn't have a valid insertion location.
As a result of that any file ID created for an include inside the
predefined buffers breaks the traversal logic in
SourceManager::computeMacroArgsCache.
To fix this issue we first record number of created FIDs for predefined
buffer, and then skip them explicitly in source manager.
Another solution would be to just give predefined buffers a valid source
location, but it is unclear where that should be..
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78649
Diffstat (limited to 'clang/unittests/Basic/SourceManagerTest.cpp')
-rw-r--r-- | clang/unittests/Basic/SourceManagerTest.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp index f4bdd9c..850a08b 100644 --- a/clang/unittests/Basic/SourceManagerTest.cpp +++ b/clang/unittests/Basic/SourceManagerTest.cpp @@ -294,10 +294,16 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) { TrivialModuleLoader ModLoader; HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr, Diags, LangOpts, &*Target); + Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader, /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false); + // Ensure we can get expanded locations in presence of implicit includes. + // These are different than normal includes since predefines buffer doesn't + // have a valid insertion location. + PP.setPredefines("#include \"/implicit-header.h\""); + FileMgr.getVirtualFile("/implicit-header.h", 0, 0); PP.Initialize(*Target); PP.EnterMainSourceFile(); |