summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-02-21 05:45:29 +0000
committerChris Lattner <sabre@nondot.org>2008-02-21 05:45:29 +0000
commit3b418d8446458c82d77fe35fb3824c5acc752e09 (patch)
tree3e62c6e47ad774d629249b634328f0c8cfc77bf9 /clang/CodeGen/CGExprScalar.cpp
parent4da4f85090280d794a75332b096f1bea82dd0255 (diff)
downloadbcm5719-llvm-3b418d8446458c82d77fe35fb3824c5acc752e09.tar.gz
bcm5719-llvm-3b418d8446458c82d77fe35fb3824c5acc752e09.zip
implement codegen support for sizeof(void), fixing PR2080.
llvm-svn: 47429
Diffstat (limited to 'clang/CodeGen/CGExprScalar.cpp')
-rw-r--r--clang/CodeGen/CGExprScalar.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/CodeGen/CGExprScalar.cpp b/clang/CodeGen/CGExprScalar.cpp
index 2c7763db8f2..85831d5dd36 100644
--- a/clang/CodeGen/CGExprScalar.cpp
+++ b/clang/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));
}
OpenPOWER on IntegriCloud