[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper

2023-02-14 Thread Raphael Isemann via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f3a3e1f3f97: [lldb] Disable macro redefinition warnings in 
expression wrapper (authored by teemperor).

Repository:
  rG LLVM Github Monorepo

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 << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  = 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 << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  = dm->GetMacroEntryAtIndex(i);
 uint32_t line;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper

2023-02-14 Thread Raphael Isemann via Phabricator via lldb-commits
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 << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  = 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 << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  = dm->GetMacroEntryAtIndex(i);
 uint32_t line;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper

2022-12-10 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp:150
+  stream << "#pragma clang diagnostic push\n";
+  stream << "#pragma clang diagnostic ignored \"-Wmacro-redefined\"\n";
+  auto pop_warning = llvm::make_scope_exit([](){

You might want to also add `-Wbuiltin-macro-redefined`

Just tried this change on my Ubuntu VM with gcc-11 and it gets rid of most 
diagnostics apart from one:

```
(lldb) p alksjdh
  
error: expression failed to parse:  
  
warning: :252:9: redefining builtin macro  
   
#define __FLT_EVAL_METHOD__ 0   
  
^   
  
error: :1:1: use of undeclared identifier 'alksjdh'  
  
alksjdh 
  
^   
  
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139740/new/

https://reviews.llvm.org/D139740

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper

2022-12-10 Thread Michael Buch via Phabricator via lldb-commits
Michael137 accepted this revision.
Michael137 added a comment.
This revision is now accepted and ready to land.

LGTM thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139740/new/

https://reviews.llvm.org/D139740

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper

2022-12-09 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added a reviewer: Michael137.
teemperor added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
teemperor requested review of this revision.
Herald added a subscriber: lldb-commits.

GCC emits macro definitions into debug info when compiling with `-g3`.
LLDB is translating this information into `#define` directives which are 
injected into the
source code of user expressions. While this mechanism itself works fine, it can 
lead to
spurious "... macro redefined" warnings when the defined macro is also a 
builtin Clang macro:

  warning: :46:9: '__VERSION__' macro redefined
  #define __VERSION__ "12.1.0"
  ^
  :19:9: previous definition is here
  #define __VERSION__ "Clang 14.0.6"
  [repeated about a 100 more times for every builtin macro]

This patch just disables the diagnostic when parsing LLDB's generated list of
macros definitions.


Repository:
  rG LLVM Github Monorepo

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,8 @@
 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()))
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,16 @@
   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";
+  auto pop_warning = llvm::make_scope_exit([](){
+stream << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  = 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,8 @@
 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()))
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,16 @@
   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";
+  auto pop_warning = llvm::make_scope_exit([](){
+stream << "#pragma clang diagnostic pop\n";
+  });
+
   for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) {
 const DebugMacroEntry  =