[cfe-commits] r151403 - in /cfe/trunk: lib/CodeGen/CodeGenTypes.cpp test/CodeGenCXX/forward-enum.cpp
Douglas Gregor
dgregor at apple.com
Fri Feb 24 14:40:36 PST 2012
Author: dgregor
Date: Fri Feb 24 16:40:36 2012
New Revision: 151403
URL: http://llvm.org/viewvc/llvm-project?rev=151403&view=rev
Log:
For the purposes of building LLVM types, a forward-declared
enumeration type with a fixed underlying type is complete. Fixes
<rdar://problem/10916155>.
Added:
cfe/trunk/test/CodeGenCXX/forward-enum.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=151403&r1=151402&r2=151403&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Fri Feb 24 16:40:36 2012
@@ -199,8 +199,13 @@
// If it's a tagged type used by-value, but is just a forward decl, we can't
// convert it. Note that getDefinition()==0 is not the same as !isDefinition.
- if (TT->getDecl()->getDefinition() == 0)
+ // The exception is an enumeration type with a fixed underlying type; these
+ // can be converted even if they are forward declarations.
+ if (TT->getDecl()->getDefinition() == 0 &&
+ !(isa<EnumDecl>(TT->getDecl()) &&
+ cast<EnumDecl>(TT->getDecl())->isFixed())) {
return false;
+ }
// If this is an enum, then it is always safe to convert.
const RecordType *RT = dyn_cast<RecordType>(TT);
Added: cfe/trunk/test/CodeGenCXX/forward-enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/forward-enum.cpp?rev=151403&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/forward-enum.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/forward-enum.cpp Fri Feb 24 16:40:36 2012
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11.0.0 -emit-llvm -o - %s | FileCheck %s
+
+enum MyEnum : char;
+void bar(MyEnum value) { }
+
+// CHECK: define void @_Z3foo6MyEnum
+void foo(MyEnum value)
+{
+ // CHECK: call void @_Z3bar6MyEnum(i8 signext
+ bar(value);
+}
More information about the cfe-commits
mailing list