[clang] 8b63622 - [clang][extract-api] Undefining macros should not result in a crash
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 5 03:43:17 PDT 2022
Author: Daniel Grumberg
Date: 2022-04-05T11:42:45+01:00
New Revision: 8b63622b9fd9ad2a86487da6098b7a4351d3e8eb
URL: https://github.com/llvm/llvm-project/commit/8b63622b9fd9ad2a86487da6098b7a4351d3e8eb
DIFF: https://github.com/llvm/llvm-project/commit/8b63622b9fd9ad2a86487da6098b7a4351d3e8eb.diff
LOG: [clang][extract-api] Undefining macros should not result in a crash
This fixes the situation where a undefining a not previously defined
macro resulted in a crash. Before trying to remove a definition from
PendingMacros we first check to see if the macro did indeed have a
previous definition.
Differential Revision: https://reviews.llvm.org/D123056
Added:
Modified:
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/test/ExtractAPI/macro_undefined.c
Removed:
################################################################################
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index cf95c3d739b60..e4ae0403f260f 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -534,6 +534,11 @@ class MacroCallback : public PPCallbacks {
// 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();
diff --git a/clang/test/ExtractAPI/macro_undefined.c b/clang/test/ExtractAPI/macro_undefined.c
index e04712500ef93..f128a446b6588 100644
--- a/clang/test/ExtractAPI/macro_undefined.c
+++ b/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
{
More information about the cfe-commits
mailing list