From e853bb34ec1f86e12dcdaa9b5e782fac2117b08f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 1 Mar 2012 23:42:00 +0000 Subject: [PATCH] c/objc: problem originally reported as an objective-c bug. But it is in the underlying c part of clang. clang crashes in IRGen when passing an incomplete type argument to variadic function (instead of diagnosing the bug). // rdar://10961370 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151862 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 6 ++++++ test/Sema/variadic-incomplete-arg-type.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/Sema/variadic-incomplete-arg-type.c diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 149201192f..6deffa2abd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -587,6 +587,12 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, E = Comma.get(); } } + // c++ rules are enfroced elsewhere. + if (!getLangOptions().CPlusPlus && + !E->getType()->isVoidType() && + RequireCompleteType(E->getExprLoc(), E->getType(), + diag::err_incomplete_type)) + return ExprError(); return Owned(E); } diff --git a/test/Sema/variadic-incomplete-arg-type.c b/test/Sema/variadic-incomplete-arg-type.c new file mode 100644 index 0000000000..1306173a0e --- /dev/null +++ b/test/Sema/variadic-incomplete-arg-type.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +// rdar://10961370 + +typedef struct __CFError * CFErrorRef; // expected-note {{forward declaration of 'struct __CFError'}} + +void junk(int, ...); + +int main() +{ + CFErrorRef error; + junk(1, *error); // expected-error {{incomplete type 'struct __CFError' where a complete type is required}} +} -- 2.50.1