[clang] [clang][NFC] Suppress octal literal warnings in system macros via TableGen (PR #228035)

Shengxin Pei via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 05:23:56 PDT 2026


https://github.com/TPPPP72 updated https://github.com/llvm/llvm-project/pull/228035

>From f3df0b7a7d3120cde502f5f2775ac118b04fff42 Mon Sep 17 00:00:00 2001
From: Shengxin Pei <TPPPP72 at outlook.com>
Date: Thu, 1 Oct 2026 18:58:15 +0800
Subject: [PATCH] [clang] Suppress octal literal warnings in system macros via
 TableGen

---
 clang/include/clang/Basic/DiagnosticLexKinds.td |  8 ++++----
 clang/lib/Lex/LiteralSupport.cpp                | 16 +++-------------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ff51485a1810b..3389890d1b2c1 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -269,16 +269,16 @@ def err_hex_constant_requires : Error<
 def ext_hex_constant_invalid : Extension<
   "hexadecimal floating constants are a C99 feature">, InGroup<C99>;
 def ext_octal_literal : Extension<
-  "octal integer literals are a C2y extension">, InGroup<C2y>;
+  "octal integer literals are a C2y extension">, InGroup<C2y>, SuppressInSystemMacro;
 def ext_cpp_octal_literal : Extension<
   "octal integer literals are a Clang extension">,
-  InGroup<DiagGroup<"octal-prefix-extension">>;
+  InGroup<DiagGroup<"octal-prefix-extension">>, SuppressInSystemMacro;
 def warn_c2y_compat_octal_literal : Warning<
   "octal integer literals are incompatible with standards before C2y">,
-  InGroup<CPre2yCompat>, DefaultIgnore;
+  InGroup<CPre2yCompat>, DefaultIgnore, SuppressInSystemMacro;
 def warn_unprefixed_octal_deprecated : Warning<
   "octal literals without a '0o' prefix are deprecated">,
-  InGroup<DeprecatedOctalLiterals>;
+  InGroup<DeprecatedOctalLiterals>, SuppressInSystemMacro;
 def ext_binary_literal : Extension<
   "binary integer literals are a C23 extension">, InGroup<C23>;
 def warn_c23_compat_binary_literal : Warning<
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index d8cceec27e101..efb1138b46615 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1495,14 +1495,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
       DiagId = diag::ext_cpp_octal_literal;
     else
       DiagId = diag::ext_octal_literal;
-    // If the token location is from a macro expansion where the macro was
-    // defined in a system header, suppress the diagnostic.
-    // FIXME: this is actually a more general issue, for example we have a
-    // similar need for binary literals above. It would be best for this to be
-    // handled by the diagnostics engine instead of with ad hoc solutions. This
-    // same concern exists below for issuing the deprecation warning.
-    if (!SM.isInSystemMacro(TokLoc))
-      Diags.Report(TokLoc, DiagId);
+    Diags.Report(TokLoc, DiagId);
 
     ++s;
     DigitsBegin = s;
@@ -1524,11 +1517,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
 
   llvm::scope_exit _([&] {
     // If we still have an octal value but we did not see an octal prefix,
-    // diagnose as being an obsolescent feature starting in C2y. If the token
-    // location is from a macro expansion where the macro was defined in a
-    // system header, suppress the diagnostic.
-    if (radix == 8 && LangOpts.C2y && !hadError && !IsSingleZero &&
-        !SM.isInSystemMacro(TokLoc))
+    // diagnose as being an obsolescent feature starting in C2y.
+    if (radix == 8 && LangOpts.C2y && !hadError && !IsSingleZero)
       Diags.Report(TokLoc, diag::warn_unprefixed_octal_deprecated);
   });
 



More information about the cfe-commits mailing list