summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-07-31 06:31:19 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-07-31 06:31:19 +0000
commit77be48ac4744554b08b9a6587a4ade8601c9cc90 (patch)
treec1087a1b801effbd2418a6b09d1e749410ea6590 /clang/lib/CodeGen/CGExprConstant.cpp
parentc537bd2da4c07c56dfa49a8bc593e4e61a84c5d2 (diff)
downloadbcm5719-llvm-77be48ac4744554b08b9a6587a4ade8601c9cc90.tar.gz
bcm5719-llvm-77be48ac4744554b08b9a6587a4ade8601c9cc90.zip
PR18097: Support initializing an _Atomic(T) from an object of C++ class type T
or a class derived from T. We already supported this when initializing _Atomic(T) from T for most (and maybe all) other reasonable values of T. llvm-svn: 214390
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index b2f08c32d92..b508dcb446f 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1045,6 +1045,25 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value,
QualType DestType,
CodeGenFunction *CGF) {
+ // For an _Atomic-qualified constant, we may need to add tail padding.
+ if (auto *AT = DestType->getAs<AtomicType>()) {
+ QualType InnerType = AT->getValueType();
+ auto *Inner = EmitConstantValue(Value, InnerType, CGF);
+
+ uint64_t InnerSize = Context.getTypeSize(InnerType);
+ uint64_t OuterSize = Context.getTypeSize(DestType);
+ if (InnerSize == OuterSize)
+ return Inner;
+
+ assert(InnerSize < OuterSize && "emitted over-large constant for atomic");
+ llvm::Constant *Elts[] = {
+ Inner,
+ llvm::ConstantAggregateZero::get(
+ llvm::ArrayType::get(Int8Ty, (OuterSize - InnerSize) / 8))
+ };
+ return llvm::ConstantStruct::getAnon(Elts);
+ }
+
switch (Value.getKind()) {
case APValue::Uninitialized:
llvm_unreachable("Constant expressions should be initialized.");
OpenPOWER on IntegriCloud