Avoid dynamic mapping to self for reverse macro dependency
Commit 04f1c92537
added a mechanism that
dynamically adds a mapping from the includee to the includer in this
case:
// a.h
#if CONTROL_FLAG
void foo();
#else
void bar();
#endif
// b.h
#define CONTROL_FLAG
#include "a.h"
However, there was no check that includee and includer were different,
so regular #include guards would cause self-mappings, which would
eventually lead to cycles in mappings and assertion failures, e.g.:
Cycle in include-mapping:
<z.hpp> ->
<z.hpp>
,,,/iwyu_include_picker.cc:845: Assertion failed: Cycle in include-mapping
Aborted
Avoid this by checking if the file defining the macro is the same as the
file using it; in that case we don't need a mapping.
This commit is contained in:
parent
6d5414fcf3
commit
616927dec4
|
@ -2120,6 +2120,10 @@ void IwyuFileInfo::HandlePreprocessingDone() {
|
|||
<< " as public header for " << private_include
|
||||
<< " because latter is already marked as public,"
|
||||
<< " though uses macro defined by includer.\n";
|
||||
} else if (file_ == macro_use_includee) {
|
||||
ERRSYM(file_) << "Skip marking " << quoted_file_
|
||||
<< " as public header for " << private_include
|
||||
<< " because they are the same file.\n";
|
||||
} else {
|
||||
ERRSYM(file_) << "Mark " << quoted_file_
|
||||
<< " as public header for " << private_include
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//===--- self_map_cycle-d1.h - test input file for iwyu -------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_SELF_MAP_CYCLE_D1_H_
|
||||
#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_SELF_MAP_CYCLE_D1_H_
|
||||
|
||||
#include "tests/cxx/self_map_cycle-d1.h"
|
||||
|
||||
struct X {
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
//===--- self_map_cycle.cc - test input file for iwyu ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// IWYU_ARGS: -I .
|
||||
|
||||
// Test that self-includes do not create a mapping cycle, which would later be
|
||||
// detected and abort with assertion failure (as described in issue #424).
|
||||
|
||||
// Note that "" #include was required to trigger the assertion here.
|
||||
#include "tests/cxx/self_map_cycle-d1.h"
|
||||
|
||||
X x;
|
||||
|
||||
/**** IWYU_SUMMARY
|
||||
|
||||
(tests/cxx/self_map_cycle.cc has correct #includes/fwd-decls)
|
||||
|
||||
***** IWYU_SUMMARY */
|
Loading…
Reference in New Issue