https://github.com/KFAFSP updated 
https://github.com/llvm/llvm-project/pull/179356

>From 2ae299875f67493a763daa8a95fb721329642eab Mon Sep 17 00:00:00 2001
From: Karl Friebel <[email protected]>
Date: Tue, 3 Feb 2026 00:12:32 +0100
Subject: [PATCH] [Clang] Fix FixIt for implicit-int diagnostics.

When encountering a declaration without a type
specifier, in contexts where they could reasonably
be assumed to default to int, clang emits a
diagnostic with FixIt. This FixIt does not produce
working code.

This patch updates SemaType to correctly insert
a single int type specifier per group of
declarations, and adds coverage in the FixIt
lit test suite.

Fixes #179354
---
 clang/lib/Sema/SemaType.cpp | 8 ++++++--
 clang/test/FixIt/fixit.c    | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 91d36f0502d85..81924830ea087 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -980,7 +980,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
     if (S.getLangOpts().isImplicitIntRequired()) {
       S.Diag(DeclLoc, diag::warn_missing_type_specifier)
           << DS.getSourceRange()
-          << FixItHint::CreateInsertion(DS.getBeginLoc(), "int");
+          << FixItHint::CreateInsertion(DS.getBeginLoc(),
+                                        declarator.isFirstDeclarator() ?
+                                        "int " : "");
     } else if (!DS.hasTypeSpecifier()) {
       // C99 and C++ require a type specifier.  For example, C99 6.7.2p2 says:
       // "At least one type specifier shall be given in the declaration
@@ -1004,7 +1006,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
&state) {
                "implicit int is disabled?");
         S.Diag(DeclLoc, diag::ext_missing_type_specifier)
             << DS.getSourceRange()
-            << FixItHint::CreateInsertion(DS.getBeginLoc(), "int");
+            << FixItHint::CreateInsertion(DS.getBeginLoc(),
+                                          declarator.isFirstDeclarator() ?
+                                          "int " : "");
       }
     }
 
diff --git a/clang/test/FixIt/fixit.c b/clang/test/FixIt/fixit.c
index 0e86d454a0e10..3338dc98638d0 100644
--- a/clang/test/FixIt/fixit.c
+++ b/clang/test/FixIt/fixit.c
@@ -27,6 +27,15 @@ struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}
 // CHECK: int array0[5] = { [3] = 3 };
 int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}
 
+// CHECK: int imp0[4],imp1,imp2=5;
+imp0[4],imp1,imp2=5; // expected-error 3{{type specifier missing, defaults to 
'int'}}
+
+// CHECK: int f2(void)
+f2(void) // expected-error {{type specifier missing, defaults to 'int'}}
+{
+  return 0;
+}
+
 // CHECK: int x
 // CHECK: int y
 void f1(x, y) // expected-error 2{{was not declared, defaults to 'int'; ISO 
C99 and later do not support implicit int}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to