r173918 - Also promote fp16 types to double when they're anonymous variadic arguments.
Tim Northover
Tim.Northover at arm.com
Wed Jan 30 01:46:56 PST 2013
Author: tnorthover
Date: Wed Jan 30 03:46:55 2013
New Revision: 173918
URL: http://llvm.org/viewvc/llvm-project?rev=173918&view=rev
Log:
Also promote fp16 types to double when they're anonymous variadic arguments.
__fp16 isn't covered by the standard, but this resolves the oddity that float
gets promoted when passed variadically, but not the smaller type. This is
required by the AArch64 ABI, and a sane action elsewhere.
Added:
cfe/trunk/test/Sema/variadic-promotion.c (with props)
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=173918&r1=173917&r2=173918&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jan 30 03:46:55 2013
@@ -581,8 +581,9 @@ ExprResult Sema::UsualUnaryConversions(E
}
/// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
-/// do not have a prototype. Arguments that have type float are promoted to
-/// double. All other argument types are converted by UsualUnaryConversions().
+/// do not have a prototype. Arguments that have type float or __fp16
+/// are promoted to double. All other argument types are converted by
+/// UsualUnaryConversions().
ExprResult Sema::DefaultArgumentPromotion(Expr *E) {
QualType Ty = E->getType();
assert(!Ty.isNull() && "DefaultArgumentPromotion - missing type");
@@ -592,8 +593,11 @@ ExprResult Sema::DefaultArgumentPromotio
return Owned(E);
E = Res.take();
- // If this is a 'float' (CVR qualified or typedef) promote to double.
- if (Ty->isSpecificBuiltinType(BuiltinType::Float))
+ // If this is a 'float' or '__fp16' (CVR qualified or typedef) promote to
+ // double.
+ const BuiltinType *BTy = Ty->getAs<BuiltinType>();
+ if (BTy && (BTy->getKind() == BuiltinType::Half ||
+ BTy->getKind() == BuiltinType::Float))
E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).take();
// C++ performs lvalue-to-rvalue conversion as a default argument
Added: cfe/trunk/test/Sema/variadic-promotion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/variadic-promotion.c?rev=173918&view=auto
==============================================================================
--- cfe/trunk/test/Sema/variadic-promotion.c (added)
+++ cfe/trunk/test/Sema/variadic-promotion.c Wed Jan 30 03:46:55 2013
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+
+void variadic(int, ...);
+
+void test_floating_promotion(__fp16 *f16, float f32, double f64) {
+ variadic(3, *f16, f32, f64);
+
+// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
+// CHECK-NEXT: 'half'
+
+// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
+// CHECK-NEXT: 'float'
+}
Propchange: cfe/trunk/test/Sema/variadic-promotion.c
------------------------------------------------------------------------------
svn:eol-style = native
More information about the cfe-commits
mailing list