diff options
-rw-r--r-- | lib/CodeGen/CodeGenTypes.cpp | 7 | ||||
-rw-r--r-- | test/CodeGenCXX/forward-enum.cpp | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 03465199a0..2da6cf0f2d 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -199,8 +199,13 @@ bool CodeGenTypes::isFuncTypeArgumentConvertible(QualType Ty) { // 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); diff --git a/test/CodeGenCXX/forward-enum.cpp b/test/CodeGenCXX/forward-enum.cpp new file mode 100644 index 0000000000..c1169e0139 --- /dev/null +++ b/test/CodeGenCXX/forward-enum.cpp @@ -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); +} |