Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -8160,6 +8160,19 @@ if (!rmerge.isNull()) return rmerge; + if (!getLangOpts().CPlusPlus) { + // Builtins that take a reference to a __builtin_va_list in some cases can be + // of the type char*&. Since this is illegal in C and caught in an assert in + // mergeTypes, remove the reference. The user cannot 'type' a char*&, so this + // should be a good assumption. + if (const auto *RefTy = lhs->getAs()) { + QualType VaListTy{getBuiltinVaListDecl()->getTypeForDecl(), 0}; + if (RefTy->getPointeeType().getCanonicalType() == + VaListTy.getCanonicalType()) + lhs = RefTy->getPointeeType(); + } + } + return mergeTypes(lhs, rhs, OfBlockPointer, Unqualified); } Index: test/Sema/va_list_builtin_func_redecl.c =================================================================== --- test/Sema/va_list_builtin_func_redecl.c +++ test/Sema/va_list_builtin_func_redecl.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-unknown-pc %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple=i386-unknown-pc %s +// expected-no-diagnostics + +void __builtin_va_end(__builtin_va_list); +int vprintf(const char*, __builtin_va_list); +int __builtin___vprintf_chk(int, const char*, __builtin_va_list); Index: test/Sema/va_list_builtin_func_redecl_errors.c =================================================================== --- test/Sema/va_list_builtin_func_redecl_errors.c +++ test/Sema/va_list_builtin_func_redecl_errors.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-unknown-pc %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple=i386-unknown-pc %s + +// expected-error@+2{{conflicting types for '__builtin_va_end'}} +// expected-note@+1{{'__builtin_va_end' is a builtin with type}} +void __builtin_va_end(void*); + +// expected-error@+2{{conflicting types for '__builtin___vprintf_chk'}} +// expected-note@+1{{'__builtin___vprintf_chk' is a builtin with type}} +int __builtin___vprintf_chk(int, const char*, void*); + +// expected-warning@+2{{incompatible redeclaration of library function 'vprintf'}} +// expected-note@+1{{'vprintf' is a builtin with type}} +int vprintf(const char*, void*);