diff options
author | Chris Lattner <sabre@nondot.org> | 2008-02-21 05:45:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-02-21 05:45:29 +0000 |
commit | a269ebfd91c4fa47e051fa1fa904833a022fe025 (patch) | |
tree | 641378dbf7e2bbfa9040166b87be60cf787d0cad /CodeGen/CGExprScalar.cpp | |
parent | 7380466f2e9a5c835344454444cd3ad89ccca6e6 (diff) |
implement codegen support for sizeof(void), fixing PR2080.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47429 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CGExprScalar.cpp')
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index 2c7763db8f..85831d5dd3 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -607,6 +607,15 @@ Value *ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *E) { /// an integer (RetType). Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, QualType RetType,bool isSizeOf){ + assert(RetType->isIntegerType() && "Result type must be an integer!"); + uint32_t ResultWidth = + static_cast<uint32_t>(CGF.getContext().getTypeSize(RetType, + SourceLocation())); + + // sizeof(void) and __alignof__(void) = 1 as a gcc extension. + if (TypeToSize->isVoidType()) + return llvm::ConstantInt::get(llvm::APInt(ResultWidth, 1)); + /// FIXME: This doesn't handle VLAs yet! std::pair<uint64_t, unsigned> Info = CGF.getContext().getTypeInfo(TypeToSize, SourceLocation()); @@ -614,10 +623,6 @@ Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, uint64_t Val = isSizeOf ? Info.first : Info.second; Val /= 8; // Return size in bytes, not bits. - assert(RetType->isIntegerType() && "Result type must be an integer!"); - - uint32_t ResultWidth = static_cast<uint32_t>( - CGF.getContext().getTypeSize(RetType, SourceLocation())); return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); } |