From 0a1e349a7933f7880971533175e11b4bfd22bd53 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 13 Dec 2019 14:44:06 -0800 Subject: [PATCH] [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 --- clang/lib/Sema/SemaDeclAttr.cpp | 4 ++-- clang/test/CodeGen/wasm-export-name.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e83688c46be1e..678320487453e 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 b662a272cbaca..f2556155dd4cf 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" {{.*}}}