This revision was automatically updated to reflect the committed changes. Closed by commit rG8b63622b9fd9: [clang][extract-api] Undefining macros should not result in a crash (authored by dang).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123056/new/ https://reviews.llvm.org/D123056 Files: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp clang/test/ExtractAPI/macro_undefined.c Index: clang/test/ExtractAPI/macro_undefined.c =================================================================== --- clang/test/ExtractAPI/macro_undefined.c +++ clang/test/ExtractAPI/macro_undefined.c @@ -19,6 +19,8 @@ FUNC_GEN(foo) FUNC_GEN(bar, const int *, unsigned); #undef FUNC_GEN +// Undefining a not previously defined macro should not result in a crash. +#undef FOO //--- reference.output.json.in { Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp =================================================================== --- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -534,6 +534,11 @@ // macro definition for it. void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD, const MacroDirective *Undef) override { + // If this macro wasn't previously defined we don't need to do anything + // here. + if (!Undef) + return; + llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) { return MD.getMacroInfo()->getDefinitionLoc() == PM.MD->getMacroInfo()->getDefinitionLoc();
Index: clang/test/ExtractAPI/macro_undefined.c =================================================================== --- clang/test/ExtractAPI/macro_undefined.c +++ clang/test/ExtractAPI/macro_undefined.c @@ -19,6 +19,8 @@ FUNC_GEN(foo) FUNC_GEN(bar, const int *, unsigned); #undef FUNC_GEN +// Undefining a not previously defined macro should not result in a crash. +#undef FOO //--- reference.output.json.in { Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp =================================================================== --- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -534,6 +534,11 @@ // macro definition for it. void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD, const MacroDirective *Undef) override { + // If this macro wasn't previously defined we don't need to do anything + // here. + if (!Undef) + return; + llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) { return MD.getMacroInfo()->getDefinitionLoc() == PM.MD->getMacroInfo()->getDefinitionLoc();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits