[PATCH] D73846: [PCH] make sure to not warn about unused macros from -D

Luboš Luňák via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 21 15:11:48 PDT 2020


llunak added a comment.

In D73846#1991330 <https://reviews.llvm.org/D73846#1991330>, @rsmith wrote:

> Looks OK as a workaround. Do you know why we consider these to be in the main file? If we could fix that in the source manager, that'd seem preferable.


According to my testing, SourceManager::isInMainFile() can handle "<built-in>" locations in 3 ways:

- for macros defined using -D on the command line the control flow returns false in the "if (FI.hasLineDirectives())" block
- for built-in macros such as __clang__ the control flow enters the same "if (FI.hasLineDirectives())" block, but Entry->IncludeOffset is 0, so the flow then reaches the final "return FI.getIncludeLoc().isInvalid();", which returns true
- if PCH is used, macros defined using -D on the command line do not even enter "if (FI.hasLineDirectives())" and so they end up returning true the same way built-in macros do

But I don't understand this enough to know why and what that actually means.

I've also tried a patch that added SourceManager::setPredefinesFileID() and moved the check from this patch to SourceManager::isInMainFile(), but then tests fail because apparently Preprocessor::setPredefinesFileID() may be called multiple times.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73846/new/

https://reviews.llvm.org/D73846





More information about the cfe-commits mailing list