From d5668a2447c2afeea38815b51a80a5a6ac235599 Mon Sep 17 00:00:00 2001
From: Argyrios Kyrtzidis <akyrtzi@gmail.com>
Date: Fri, 22 Feb 2013 06:58:32 +0000
Subject: [PATCH] When a parameter list in a C function has an error, recover
 by forming a K&R function, instead of a non-function type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175868 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaType.cpp    | 2 ++
 test/Sema/alloc_size.c   | 2 +-
 test/Sema/invalid-decl.c | 4 ++++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 209699f4b8e..c47a7f59ac0 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -2580,6 +2580,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
           // definition.
           S.Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration);
           D.setInvalidType(true);
+          // Recover by creating a K&R-style function type.
+          T = Context.getFunctionNoProtoType(T);
           break;
         }
 
diff --git a/test/Sema/alloc_size.c b/test/Sema/alloc_size.c
index 6a580b5a809..84f39320465 100644
--- a/test/Sema/alloc_size.c
+++ b/test/Sema/alloc_size.c
@@ -23,5 +23,5 @@ void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // exp
 
 void* fn10(size_t, size_t) __attribute__((alloc_size(1,2))); // expected-error{{redefinition of parameter}} \
                                                              // expected-error{{a parameter list without types is only allowed in a function definition}} \
-                                                             // expected-warning{{alloc_size attribute only applies to functions and methods}}
+                                                             // expected-error{{attribute parameter 1 is out of bounds}}
 void* fn11() __attribute__((alloc_size(1))); // expected-error{{attribute parameter 1 is out of bounds}}
diff --git a/test/Sema/invalid-decl.c b/test/Sema/invalid-decl.c
index b2c2aaf1a0f..4e628817d22 100644
--- a/test/Sema/invalid-decl.c
+++ b/test/Sema/invalid-decl.c
@@ -38,3 +38,7 @@ static void bar(hid_t p, char); // expected-error {{unknown type name 'hid_t'}}
 void foo() {
   (void)bar;
 }
+
+void test2();
+void test2(undef); // expected-error {{a parameter list without types is only allowed in a function definition}}
+void test2() { }
-- 
GitLab