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
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp
index 2c7763d..85831d5 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -607,6 +607,15 @@
 /// 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 @@
   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));
 }