[Macros] Be deliberate about walking macro arguments vs. expansions

Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
This commit is contained in:
Doug Gregor
2023-02-28 07:49:13 -08:00
parent 16baee3771
commit 200f2340d9
67 changed files with 590 additions and 36 deletions

View File

@@ -58,8 +58,8 @@ private:
return false;
}
bool shouldWalkMacroExpansions() override {
return SEWalker.shouldWalkMacroExpansions();
MacroWalking getMacroWalkingBehavior() const override {
return SEWalker.getMacroWalkingBehavior();
}
PreWalkAction walkToDeclPre(Decl *D) override;
@@ -687,7 +687,7 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) {
// FIXME: This should be getSemanticAttrs if we want to walk macro
// expansions. We've just already typechecked and this list is mutable so...
for (auto *customAttr : D->getAttrs().getAttributes<CustomAttr, true>()) {
if (!shouldWalkMacroExpansions() &&
if (!shouldWalkMacroArgumentsAndExpansion().second &&
D->getModuleContext()->isInGeneratedBuffer(customAttr->getLocation()))
continue;