Skip to content

Fix global constants cleanup in clang-offload-bundler #4356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/test/Driver/clang-offload-bundler-tgtsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@

const __attribute__((opencl_constant)) char const_as[] = "abc";

extern void my_printf(__attribute__((opencl_constant)) const char *fmt);

extern void undefined_func(void);

void foo(void) {
// We aim to create a gep operator in LLVM IR to have a use of const_as
my_printf(&const_as[1]);
undefined_func();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ class ObjectFileHandler final : public FileHandler {
// Do not add globals with constant address space to the tgtsym.
if (!GV.isDeclaration() && !GV.hasLocalLinkage() &&
GV.getAddressSpace() == 2) {
GV.replaceAllUsesWith(UndefValue::get(GV.getType()));
GV.dropAllReferences();
GV.eraseFromParent();
UpdateBuf = true;
Expand Down