[cfe-commits] r71942 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/va_arg_x86_32.c
Eli Friedman
eli.friedman at gmail.com
Sat May 16 05:46:57 PDT 2009
Author: efriedma
Date: Sat May 16 07:46:54 2009
New Revision: 71942
URL: http://llvm.org/viewvc/llvm-project?rev=71942&view=rev
Log:
Add stricter checking for va_arg.
Added:
cfe/trunk/test/Sema/va_arg_x86_32.c
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71942&r1=71941&r2=71942&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat May 16 07:46:54 2009
@@ -5208,15 +5208,21 @@
// Get the va_list type
QualType VaListType = Context.getBuiltinVaListType();
- // Deal with implicit array decay; for example, on x86-64,
- // va_list is an array, but it's supposed to decay to
- // a pointer for va_arg.
- if (VaListType->isArrayType())
+ if (VaListType->isArrayType()) {
+ // Deal with implicit array decay; for example, on x86-64,
+ // va_list is an array, but it's supposed to decay to
+ // a pointer for va_arg.
VaListType = Context.getArrayDecayedType(VaListType);
- // Make sure the input expression also decays appropriately.
- UsualUnaryConversions(E);
+ // Make sure the input expression also decays appropriately.
+ UsualUnaryConversions(E);
+ } else {
+ // Otherwise, the va_list argument must be an l-value because
+ // it is modified by va_arg.
+ if (CheckForModifiableLvalue(E, BuiltinLoc, *this))
+ return ExprError();
+ }
- if (CheckAssignmentConstraints(VaListType, E->getType()) != Compatible) {
+ if (!Context.hasSameType(VaListType, E->getType())) {
return ExprError(Diag(E->getLocStart(),
diag::err_first_argument_to_va_arg_not_of_type_va_list)
<< OrigExpr->getType() << E->getSourceRange());
Added: cfe/trunk/test/Sema/va_arg_x86_32.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/va_arg_x86_32.c?rev=71942&view=auto
==============================================================================
--- cfe/trunk/test/Sema/va_arg_x86_32.c (added)
+++ cfe/trunk/test/Sema/va_arg_x86_32.c Sat May 16 07:46:54 2009
@@ -0,0 +1,6 @@
+// RUN: clang-cc -fsyntax-only -verify -triple=i686-pc-linux-gnu %s
+
+int a() {
+ __builtin_va_arg((char*)0, int); // expected-error {{expression is not assignable}}
+ __builtin_va_arg((void*){0}, int); // expected-error {{first argument to 'va_arg' is of type 'void *'}}
+}
More information about the cfe-commits
mailing list