]> granicus.if.org Git - clang/commitdiff
Allow vectors to be constructed from constexpr function arguments in
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 13 Mar 2012 20:58:32 +0000 (20:58 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 13 Mar 2012 20:58:32 +0000 (20:58 +0000)
constant expressions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152665 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx11.cpp

index 4531a464480250612aeb1faf669c86b725b485e9..7d65cf585b5203d82b4514aec06e86ae3747ef10 100644 (file)
@@ -3743,7 +3743,7 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
       llvm::APSInt sInt(32);
       if (CountInits < NumInits) {
         if (!EvaluateInteger(E->getInit(CountInits), sInt, Info))
-          return Error(E);
+          return false;
       } else // trailing integer zero.
         sInt = Info.Ctx.MakeIntValue(0, EltTy);
       Elements.push_back(APValue(sInt));
@@ -3752,7 +3752,7 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
       llvm::APFloat f(0.0);
       if (CountInits < NumInits) {
         if (!EvaluateFloat(E->getInit(CountInits), f, Info))
-          return Error(E);
+          return false;
       } else // trailing float zero.
         f = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(EltTy));
       Elements.push_back(APValue(f));
index 66fd064fed366d0d65086b0227590754404547f5..41d214a6364bcdef16ca0a404ea05422b0072ee0 100644 (file)
@@ -1230,3 +1230,17 @@ namespace CompoundLiteral {
   // in C++, and in C we model compound literals as lvalues.
   constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expression}} expected-note 2{{temporary}}
 }
+
+namespace Vector {
+  typedef int __attribute__((vector_size(16))) VI4;
+  constexpr VI4 f(int n) {
+    return VI4 { n * 3, n + 4, n - 5, n / 6 };
+  }
+  constexpr auto v1 = f(10);
+
+  typedef double __attribute__((vector_size(32))) VD4;
+  constexpr VD4 g(int n) {
+    return (VD4) { n / 2.0, n + 1.5, n - 5.4, n * 0.9 }; // expected-warning {{C99}}
+  }
+  constexpr auto v2 = g(4);
+}