[PATCH] D58161: Print a note to the called macro when diagnosing err_embedded_directive

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 13 20:17:30 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL354009: Print a note to the called macro when diagnosing err_embedded_directive (authored by nico, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58161?vs=186574&id=186792#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58161

Files:
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPMacroExpansion.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/test/Preprocessor/macro_arg_directive.c


Index: cfe/trunk/lib/Lex/Preprocessor.cpp
===================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp
+++ cfe/trunk/lib/Lex/Preprocessor.cpp
@@ -102,6 +102,7 @@
   DisableMacroExpansion = false;
   MacroExpansionInDirectivesOverride = false;
   InMacroArgs = false;
+  ArgMacro = nullptr;
   InMacroArgPreExpansion = false;
   NumCachedTokenLexers = 0;
   PragmasEnabled = true;
Index: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
===================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp
@@ -492,10 +492,13 @@
     // Preprocessor directives used inside macro arguments are not portable, and
     // this enables the warning.
     InMacroArgs = true;
+    ArgMacro = &Identifier;
+
     Args = ReadMacroCallArgumentList(Identifier, MI, ExpansionEnd);
 
     // Finished parsing args.
     InMacroArgs = false;
+    ArgMacro = nullptr;
 
     // If there was an error parsing the arguments, bail out.
     if (!Args) return true;
Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -886,6 +886,8 @@
       case tok::pp___include_macros:
       case tok::pp_pragma:
         Diag(Result, diag::err_embedded_directive) << II->getName();
+        Diag(*ArgMacro, diag::note_macro_expansion_here)
+            << ArgMacro->getIdentifierInfo();
         DiscardUntilEndOfDirective();
         return;
       default:
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -173,6 +173,9 @@
   IdentifierInfo *Ident__is_target_os;             // __is_target_os
   IdentifierInfo *Ident__is_target_environment;    // __is_target_environment
 
+  // Weak, only valid (and set) while InMacroArgs is true.
+  Token* ArgMacro;
+
   SourceLocation DATELoc, TIMELoc;
 
   // Next __COUNTER__ value, starts at 0.
Index: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
@@ -391,6 +391,7 @@
   "empty macro arguments are incompatible with C++98">,
   InGroup<CXX98CompatPedantic>, DefaultIgnore;
 def note_macro_here : Note<"macro %0 defined here">;
+def note_macro_expansion_here : Note<"expansion of macro %0 requested here">;
 
 def err_pp_opencl_variadic_macros :
   Error<"variadic macros not supported in OpenCL">;
Index: cfe/trunk/test/Preprocessor/macro_arg_directive.c
===================================================================
--- cfe/trunk/test/Preprocessor/macro_arg_directive.c
+++ cfe/trunk/test/Preprocessor/macro_arg_directive.c
@@ -8,7 +8,7 @@
 _Static_assert(n == 5, "");
 
 #define M(A)
-M(
+M( // expected-note {{expansion of macro 'M' requested here}}
 #pragma pack(pop) // expected-error {{embedding a #pragma directive within macro arguments is not supported}}
 )
 
@@ -18,7 +18,7 @@
  ({ int result = 0; __VA_ARGS__; if (!result) { fail(#__VA_ARGS__); }; result })
 
 static inline int f(int k) {
-  return MUNCH( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{returning 'void'}}
+  return MUNCH( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{returning 'void'}} expected-note {{expansion of macro 'MUNCH' requested here}}
     if (k < 3)
       result = 24;
     else if (k > 4)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58161.186792.patch
Type: text/x-patch
Size: 3697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/3cf409a7/attachment.bin>


More information about the llvm-commits mailing list