Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -352,6 +352,21 @@ getModule().addModuleFlag(llvm::Module::Warning, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); + // We need to record the widths of enums and wchar_t, so that we can generate + // the correct build attributes in the ARM backend. + // Width of wchar_t in bytes + uint64_t WCharWidth = Context.getLangOpts().ShortWChar ? 1 : 0; + getModule().addModuleFlag(llvm::Module::Error, "short_wchar", + WCharWidth); + + // 1 => Enum values occupy the smallest container big enough to hold all + // their values. + // 2 => Enum containers are 32-bit, unless they have a value which requires + // a 64-bit container to represent. + uint64_t EnumWidth = Context.getLangOpts().ShortEnums ? 1 : 0; + getModule().addModuleFlag(llvm::Module::Error, "short_enum", EnumWidth); + + SimplifyPersonality(); if (getCodeGenOpts().EmitDeclMetadata) Index: test/CodeGen/arm-metadata.c =================================================================== --- /dev/null +++ test/CodeGen/arm-metadata.c @@ -0,0 +1,13 @@ +// REQUIRES: arm-registered-target +// RUN: %clang_cc1 -triple armv7a-linux-gnueabi -emit-llvm -o - %s | FileCheck -check-prefix=DEFAULT %s +// RUN: %clang_cc1 -triple armv7a-linux-gnueabi -emit-llvm -o - %s -fshort-enums | FileCheck -check-prefix=SHORT-ENUM %s +// RUN: %clang_cc1 -triple armv7a-linux-gnueabi -emit-llvm -o - %s -fshort-wchar | FileCheck -check-prefix=SHORT-WCHAR %s + +// DEFAULT: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_wchar", i32 0} +// DEFAULT: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_enum", i32 0} + +// SHORT-WCHAR: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_wchar", i32 1} +// SHORT-WCHAR: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_enum", i32 0} + +// SHORT_ENUM: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_wchar", i32 0} +// SHORT-ENUM: !{{[0-9]+}} = metadata !{i32 1, metadata !"short_enum", i32 1}