[PATCH] D30882: Add a callback for __has_include and use it for dependency scanning

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 14 16:45:04 PDT 2018


rsmith added inline comments.


================
Comment at: lib/Frontend/DependencyFile.cpp:325
+void DFGImpl::HasInclude(SourceLocation Loc, const FileEntry *File) {
+  if (!File)
+    return;
----------------
vsapsai wrote:
> rsmith wrote:
> > Have you thought about whether we should add a dependency even for a missing file under `-MG` (`AddMissingHeaderDeps`) mode? I think it's probably better to not do so (ie, the behavior in this patch), but it seems worth considering.
> Do you know how Make uses these missing files? Or maybe where I can find more. The only documentation I found says
> 
> > This feature is used in automatic updating of makefiles.
> 
> Which is not particularly illuminating.
> 
> Currently I prefer not to include not found `__has_include` files because they aren't really missing, it's OK if they aren't there and nothing has to be done to fix that. But I'd like to confirm if my understanding aligns with Make behaviour.
I believe the setup is this:

 * your project uses generated headers
 * in order to do the first compilation, you need to know which source files might include those generated headers

So you use `-M -MG` to build your make file dependencies as a separate step before your first "real" compilation, and the `-MG` flag causes dependencies on the not-yet-existing generated files to be emitted by the compiler.

Given that the purpose of `-MG` (as I understand it) is to cope with generated files, and that using `__has_include` to find a generated file would be peculiar (it's much more likely that the named file simply doesn't exist and shouldn't have a dependency generated for it), I think it's better to omit dependencies for nonexistent files for `__has_include` even under `-MG`.


https://reviews.llvm.org/D30882





More information about the cfe-commits mailing list