teemperor updated this revision to Diff 497440.
teemperor added a comment.
- Address builtin redefining (Thanks Michael!)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139740/new/
https://reviews.llvm.org/D139740
Files:
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
lldb/test/API/commands/expression/macros/TestMacros.py
Index: lldb/test/API/commands/expression/macros/TestMacros.py
===================================================================
--- lldb/test/API/commands/expression/macros/TestMacros.py
+++ lldb/test/API/commands/expression/macros/TestMacros.py
@@ -129,3 +129,9 @@
result = frame.EvaluateExpression("MACRO_2")
self.assertTrue(result.GetError().Fail(),
"Printing MACRO_2 fails in the header file")
+
+ # Check that the macro definitions do not trigger bogus Clang
+ # diagnostics about macro redefinitions.
+ result = frame.EvaluateExpression("does_not_parse")
+ self.assertNotIn("macro redefined", str(result.GetError()))
+ self.assertNotIn("redefining builtin macro", str(result.GetError()))
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -14,6 +14,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
@@ -141,6 +142,17 @@
if (dm == nullptr)
return;
+ // The macros directives below can potentially redefine builtin macros of the
+ // Clang instance which parses the user expression. The Clang diagnostics
+ // caused by this are not useful for the user as the source code here is
+ // generated by LLDB.
+ stream << "#pragma clang diagnostic push\n";
+ stream << "#pragma clang diagnostic ignored \"-Wmacro-redefined\"\n";
+ stream << "#pragma clang diagnostic ignored \"-Wbuiltin-macro-redefined\"\n";
+ auto pop_warning = llvm::make_scope_exit([&stream](){
+ stream << "#pragma clang diagnostic pop\n";
+ });
+
for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
const DebugMacroEntry &entry = dm->GetMacroEntryAtIndex(i);
uint32_t line;
Index: lldb/test/API/commands/expression/macros/TestMacros.py
===================================================================
--- lldb/test/API/commands/expression/macros/TestMacros.py
+++ lldb/test/API/commands/expression/macros/TestMacros.py
@@ -129,3 +129,9 @@
result = frame.EvaluateExpression("MACRO_2")
self.assertTrue(result.GetError().Fail(),
"Printing MACRO_2 fails in the header file")
+
+ # Check that the macro definitions do not trigger bogus Clang
+ # diagnostics about macro redefinitions.
+ result = frame.EvaluateExpression("does_not_parse")
+ self.assertNotIn("macro redefined", str(result.GetError()))
+ self.assertNotIn("redefining builtin macro", str(result.GetError()))
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -14,6 +14,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
@@ -141,6 +142,17 @@
if (dm == nullptr)
return;
+ // The macros directives below can potentially redefine builtin macros of the
+ // Clang instance which parses the user expression. The Clang diagnostics
+ // caused by this are not useful for the user as the source code here is
+ // generated by LLDB.
+ stream << "#pragma clang diagnostic push\n";
+ stream << "#pragma clang diagnostic ignored \"-Wmacro-redefined\"\n";
+ stream << "#pragma clang diagnostic ignored \"-Wbuiltin-macro-redefined\"\n";
+ auto pop_warning = llvm::make_scope_exit([&stream](){
+ stream << "#pragma clang diagnostic pop\n";
+ });
+
for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
const DebugMacroEntry &entry = dm->GetMacroEntryAtIndex(i);
uint32_t line;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits