[llvm] [ThinLTO] Expand test to cover same-named local var and func (PR #178761)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 13:51:41 PST 2026
https://github.com/teresajohnson created https://github.com/llvm/llvm-project/pull/178761
Enhance the test of importing of read-only (loaded from only) same named
local variables to test another case. In the new case, there is another
local of the same name in another module that is a function instead of a
variable. This test illustrates that we correctly conservatively mark
all of the summaries of that GUID as non-read only (because a function
cannot be loaded from).
This is helpful to confirm since it illustrates that once we see a
non-global variable summary on a ValueInfo (for a GUID), we can assume
that none of the other summaries are read/write-only marked global
variables (which must be imported on reference).
>From 92a3dab7c785b8e678627932228508fd87a91060 Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Thu, 29 Jan 2026 13:41:50 -0800
Subject: [PATCH] [ThinLTO] Expand test to cover same-named local var and func
Enhance the test of importing of read-only (loaded from only) same named
local variables to test another case. In the new case, there is another
local of the same name in another module that is a function instead of a
variable. This test illustrates that we correctly conservatively mark
all of the summaries of that GUID as non-read only (because a function
cannot be loaded from).
This is helpful to confirm since it illustrates that once we see a
non-global variable summary on a ValueInfo (for a GUID), we can assume
that none of the other summaries are read/write-only marked global
variables (which must be imported on reference).
---
.../X86/Inputs/local_name_conflict_var3.ll | 14 ++++++++++++++
.../test/ThinLTO/X86/local_name_conflict_var.ll | 17 ++++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/ThinLTO/X86/Inputs/local_name_conflict_var3.ll
diff --git a/llvm/test/ThinLTO/X86/Inputs/local_name_conflict_var3.ll b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict_var3.ll
new file mode 100644
index 0000000000000..979b64ec7d77f
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict_var3.ll
@@ -0,0 +1,14 @@
+; ModuleID = 'local_name_conflict_var.o'
+source_filename = "local_name_conflict_var.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define internal i32 @baz() {
+ ret i32 0
+}
+
+define i32 @b() {
+entry:
+ %is_null = icmp eq i32 ()* @baz, null
+ ret i32 0
+}
diff --git a/llvm/test/ThinLTO/X86/local_name_conflict_var.ll b/llvm/test/ThinLTO/X86/local_name_conflict_var.ll
index ed5c6e4fd4f98..0a7ab051d250b 100644
--- a/llvm/test/ThinLTO/X86/local_name_conflict_var.ll
+++ b/llvm/test/ThinLTO/X86/local_name_conflict_var.ll
@@ -4,9 +4,9 @@
; Do setup work for all below tests: generate bitcode and combined index
; RUN: opt -module-summary -module-hash %s -o %t.bc
-; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict_var1.ll -o %t2.bc
-; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict_var2.ll -o %t3.bc
-; RUN: llvm-lto -thinlto-action=thinlink -o %t4.bc %t.bc %t2.bc %t3.bc
+; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict_var1.ll -o %t1.bc
+; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict_var2.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t4.bc %t.bc %t1.bc %t2.bc
; This module will import a() and b() which should cause the read only copy
; of baz from each of those modules to be imported. Check that the both are
@@ -15,6 +15,17 @@
; IMPORT: @baz.llvm.{{.*}} = internal global i32 10
; IMPORT: @baz.llvm.{{.*}} = internal global i32 10
+;; Now do the same but linking in a 3rd module, in which baz is a local function.
+;; We should correctly mark all summaries for baz as non-read only (which doesn't
+;; make sense for a function, as you can't load from it). This should cause the
+;; linkage type of the imported copies of baz variables to be available_externally
+;; instead of internal.
+; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict_var3.ll -o %t3.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t5.bc %t.bc %t1.bc %t2.bc %t3.bc
+; RUN: llvm-lto -thinlto-action=import -exported-symbol=main %t.bc -thinlto-index=%t5.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORTNOREADONLY
+; IMPORTNOREADONLY: @baz.llvm.{{.*}} = available_externally hidden global i32 10
+; IMPORTNOREADONLY: @baz.llvm.{{.*}} = available_externally hidden global i32 10
+
; ModuleID = 'local_name_conflict_var_main.o'
source_filename = "local_name_conflict_var_main.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
More information about the llvm-commits
mailing list