[clang] 0a1e349 - [WebAssembly] Setting export_name implies llvm.used

Sam Clegg via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 14:48:52 PST 2019


Author: Sam Clegg
Date: 2019-12-16T14:48:38-08:00
New Revision: 0a1e349a7933f7880971533175e11b4bfd22bd53

URL: https://github.com/llvm/llvm-project/commit/0a1e349a7933f7880971533175e11b4bfd22bd53
DIFF: https://github.com/llvm/llvm-project/commit/0a1e349a7933f7880971533175e11b4bfd22bd53.diff

LOG: [WebAssembly] Setting export_name implies llvm.used

This change updates the clang front end to add symbols to llvm.used
when they have explicit export_name attribute.

Differential Revision: https://reviews.llvm.org/D71493

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclAttr.cpp
    clang/test/CodeGen/wasm-export-name.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e83688c46be1..678320487453 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5772,8 +5772,8 @@ static void handleWebAssemblyExportNameAttr(Sema &S, Decl *D, const ParsedAttr &
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
     return;
 
-  FD->addAttr(::new (S.Context)
-                  WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(::new (S.Context) WebAssemblyExportNameAttr(S.Context, AL, Str));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {

diff  --git a/clang/test/CodeGen/wasm-export-name.c b/clang/test/CodeGen/wasm-export-name.c
index b662a272cbac..f2556155dd4c 100644
--- a/clang/test/CodeGen/wasm-export-name.c
+++ b/clang/test/CodeGen/wasm-export-name.c
@@ -6,6 +6,8 @@ int foo(void) {
   return 43;
 }
 
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)]
+
 // CHECK: define i32 @foo() [[A:#[0-9]+]]
 
 // CHECK: attributes [[A]] = {{{.*}} "wasm-export-name"="bar" {{.*}}}


        


More information about the cfe-commits mailing list