[PATCH] Add module flags metadata to record the settings for enum and wchar width

Oliver Stannard oliver.stannard at arm.com
Fri Jun 20 02:12:36 PDT 2014


Emit the size of wchar_t and the minimum size of an enum, rather than a boolean representing which option was used.

http://reviews.llvm.org/D4212

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/arm-metadata.c

Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -352,6 +352,19 @@
     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.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
+  getModule().addModuleFlag(llvm::Module::Error, "wchar_size",
+                            WCharWidth);
+
+  // The minimum width of an enum in bytes
+  uint64_t EnumWidth = Context.getLangOpts().ShortEnums ? 1 : 4;;
+  getModule().addModuleFlag(llvm::Module::Error, "min_enum_size", 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 !"wchar_size", i32 4}
+// DEFAULT:   !{{[0-9]+}} = metadata !{i32 1, metadata !"min_enum_size", i32 4}
+
+// SHORT-WCHAR: !{{[0-9]+}} = metadata !{i32 1, metadata !"wchar_size", i32 2}
+// SHORT-WCHAR:   !{{[0-9]+}} = metadata !{i32 1, metadata !"min_enum_size", i32 4}
+
+// SHORT_ENUM:  !{{[0-9]+}} = metadata !{i32 1, metadata !"wchar_size", i32 4}
+// SHORT-ENUM:  !{{[0-9]+}} = metadata !{i32 1, metadata !"min_enum_size", i32 1}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4212.10684.patch
Type: text/x-patch
Size: 2019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140620/cd93f4de/attachment.bin>


More information about the cfe-commits mailing list