UnsignedLongTy,
NULL);
- // FIXME: This breaks an unrelated testcase in the testsuite, we
- // _want_ llvm to not use structural equality, sometimes. What
- // should we do, modify the testcase and do this anyway, or...
-#if 0
getModule().addTypeName("struct.__block_descriptor",
BlockDescriptorType);
-#endif
return BlockDescriptorType;
}
BlockDescPtrTy,
NULL);
- // FIXME: See struct.__block_descriptor
getModule().addTypeName("struct.__block_literal_generic",
GenericBlockLiteralType);
Int8PtrTy,
NULL);
- // FIXME: See struct.__block_descriptor
getModule().addTypeName("struct.__block_literal_extended_generic",
GenericExtendedBlockLiteralType);
// Get the function pointer from the literal.
llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp");
- // FIXME: second argument should be false?
- llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp");
+ llvm::Value *Func = Builder.CreateLoad(FuncPtr, false, "tmp");
// Cast the function pointer to the right type.
const llvm::Type *BlockFTy =
// See if we have already allocated an offset for this variable.
if (offset == 0) {
- int Size = CGF.CGM.getTargetData().getTypeStoreSizeInBits(Ty) / 8;
-
- unsigned Align = CGF.CGM.getContext().getTypeAlign(E->getDecl()->getType());
- if (const AlignedAttr* AA = E->getDecl()->getAttr<AlignedAttr>())
- Align = std::max(Align, AA->getAlignment());
-
// if not, allocate one now.
- offset = CGF.getBlockOffset(Size, Align);
+ offset = CGF.getBlockOffset(E->getDecl());
}
llvm::Value *BlockLiteral = CGF.LoadBlockStruct();
assert (((Align & 7) == 0)
&& "alignment must be on at least byte boundaries");
// Ensure proper alignment, even if it means we have to have a gap
- if (BlockOffset % (Align >> 3)) {
- BlockOffset += (Align >> 3) - (BlockOffset % (Align >> 3));
- assert ((BlockOffset % (Align >> 3)) == 0
- && "alignment calculation is wrong");
- }
+ BlockOffset = llvm::RoundUpToAlignment(BlockOffset, Align/8);
BlockOffset += Size;
return BlockOffset-Size;
}
+ uint64_t getBlockOffset(ValueDecl *D) {
+ uint64_t Size = getContext().getTypeSize(D->getType()) / 8;
+
+ unsigned Align = getContext().getTypeAlign(D->getType());
+ if (const AlignedAttr* AA = D->getAttr<AlignedAttr>())
+ Align = std::max(Align, AA->getAlignment());
+
+ return getBlockOffset(Size, Align);
+ }
std::map<Decl*, uint64_t> BlockDecls;
void GenerateCode(const FunctionDecl *FD,
_Complex double g1y = 1.0fi;
// RUN: grep '@g1 = global { i8, i8 } { i8 1, i8 10 }' %t &&
_Complex char g1 = (char) 1 + (char) 10 * 1i;
-// RUN: grep '@g2 = global { i32, i32 } { i32 1, i32 10 }' %t &&
+// RUN: grep '@g2 = global .struct.__block_descriptor { i32 1, i32 10 }' %t &&
_Complex int g2 = 1 + 10i;
// RUN: grep '@g3 = global { float, float } { float 1.000000e+00, float 1.000000e+01 }' %t &&
_Complex float g3 = 1.0 + 10.0i;
// RUN: grep '@g4 = global { double, double } { double 1.000000e+00, double 1.000000e+01 }' %t &&
_Complex double g4 = 1.0 + 10.0i;
-// RUN: grep '@g5 = global { i32, i32 } zeroinitializer' %t &&
+// RUN: grep '@g5 = global .struct.__block_descriptor zeroinitializer' %t &&
_Complex int g5 = (2 + 3i) == (5 + 7i);
// RUN: grep '@g6 = global { double, double } { double -1.100000e+01, double 2.900000e+01 }' %t &&
_Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i);