-
Notifications
You must be signed in to change notification settings - Fork 43
Emit global strings in the correct address space. #516
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/lib/15/libLLVM_extra.jl b/lib/15/libLLVM_extra.jl
index 8a330824..8a3ceb29 100644
--- a/lib/15/libLLVM_extra.jl
+++ b/lib/15/libLLVM_extra.jl
@@ -402,6 +402,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/lib/16/libLLVM_extra.jl b/lib/16/libLLVM_extra.jl
index 8a330824..8a3ceb29 100644
--- a/lib/16/libLLVM_extra.jl
+++ b/lib/16/libLLVM_extra.jl
@@ -402,6 +402,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/lib/17/libLLVM_extra.jl b/lib/17/libLLVM_extra.jl
index b7ef156c..4d36910a 100644
--- a/lib/17/libLLVM_extra.jl
+++ b/lib/17/libLLVM_extra.jl
@@ -362,6 +362,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/lib/18/libLLVM_extra.jl b/lib/18/libLLVM_extra.jl
index 0f7f3edf..8f2082fc 100644
--- a/lib/18/libLLVM_extra.jl
+++ b/lib/18/libLLVM_extra.jl
@@ -296,6 +296,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/lib/19/libLLVM_extra.jl b/lib/19/libLLVM_extra.jl
index 0f7f3edf..8f2082fc 100644
--- a/lib/19/libLLVM_extra.jl
+++ b/lib/19/libLLVM_extra.jl
@@ -296,6 +296,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/lib/20/libLLVM_extra.jl b/lib/20/libLLVM_extra.jl
index b9b25a7a..d69b14c9 100644
--- a/lib/20/libLLVM_extra.jl
+++ b/lib/20/libLLVM_extra.jl
@@ -248,6 +248,6 @@ function LLVMRunJuliaPassesOnFunction(F, Passes, TM, Options, Extensions)
end
function LLVMGlobalsAddressSpace(TD)
- ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
+ return ccall((:LLVMGlobalsAddressSpace, libLLVMExtra), Cuint, (LLVMTargetDataRef,), TD)
end
diff --git a/src/datalayout.jl b/src/datalayout.jl
index dc8a93fa..cebe46f6 100644
--- a/src/datalayout.jl
+++ b/src/datalayout.jl
@@ -1,7 +1,7 @@
## data layout
export DataLayout, dispose,
- byteorder, pointersize, intptr, globals_addrspace,
+ byteorder, pointersize, intptr, globals_addrspace,
sizeof, storage_size, abi_size,
abi_alignment, frame_alignment, preferred_alignment,
element_at, offsetof
@@ -57,7 +57,7 @@ Base.string(dl::DataLayout) =
unsafe_message(API.LLVMCopyStringRepOfTargetData(dl))
function Base.show(io::IO, dl::DataLayout)
- @printf(io, "DataLayout(%s)", string(dl))
+ return @printf(io, "DataLayout(%s)", string(dl))
end
"""
@@ -72,7 +72,7 @@ byteorder(dl::DataLayout) = API.LLVMByteOrder(dl)
Get the pointer size of the target data layout.
"""
-pointersize(dl::DataLayout, addrspace::Integer=0) =
+pointersize(dl::DataLayout, addrspace::Integer = 0) =
API.LLVMPointerSizeForAS(dl, addrspace)
"""
@@ -80,7 +80,7 @@ pointersize(dl::DataLayout, addrspace::Integer=0) =
Get the integer type that is the same size as a pointer for the target data layout.
"""
-intptr(dl::DataLayout, addrspace::Integer=0) =
+intptr(dl::DataLayout, addrspace::Integer = 0) =
IntegerType(API.LLVMIntPtrTypeForASInContext(context(), dl, addrspace))
"""
diff --git a/src/irbuilder.jl b/src/irbuilder.jl
index c236f22c..5f22ca42 100644
--- a/src/irbuilder.jl
+++ b/src/irbuilder.jl
@@ -523,15 +523,18 @@ not!(builder::IRBuilder, V::Value, Name::String="") =
# re-implementation for flexibility (exposing addrspace, add_null)
function globalstring!(mod::LLVM.Module, str::String, name::String="";
- addrspace::Union{Integer,Nothing}=nothing, add_null::Bool=true)
+ addrspace::Union{Integer, Nothing} = nothing, add_null::Bool = true
+ )
bytes = Vector{UInt8}(str)
if add_null
push!(bytes, 0x00)
end
constant = ConstantDataArray(bytes)
- gv = GlobalVariable(mod, value_type(constant), name,
- something(addrspace, globals_addrspace(datalayout(mod))))
+ gv = GlobalVariable(
+ mod, value_type(constant), name,
+ something(addrspace, globals_addrspace(datalayout(mod)))
+ )
alignment!(gv, 1)
unnamed_addr!(gv, true)
initializer!(gv, constant)
diff --git a/test/datalayout_tests.jl b/test/datalayout_tests.jl
index ae1bab35..6c2ad4dd 100644
--- a/test/datalayout_tests.jl
+++ b/test/datalayout_tests.jl
@@ -3,44 +3,44 @@
dlstr = "E-p:32:32-f128:128:128"
let
- dl = DataLayout(dlstr)
- dispose(dl)
+ dl = DataLayout(dlstr)
+ dispose(dl)
end
-DataLayout(dlstr) do dl
+ DataLayout(dlstr) do dl
end
-@dispose ctx=Context() dl=DataLayout(dlstr) begin
- @test string(dl) == dlstr
+ @dispose ctx = Context() dl = DataLayout(dlstr) begin
+ @test string(dl) == dlstr
- @test occursin(dlstr, sprint(io->show(io,dl)))
+ @test occursin(dlstr, sprint(io -> show(io, dl)))
- @test byteorder(dl) == LLVM.API.LLVMBigEndian
- @test pointersize(dl) == pointersize(dl, 0) == 4
+ @test byteorder(dl) == LLVM.API.LLVMBigEndian
+ @test pointersize(dl) == pointersize(dl, 0) == 4
- @test intptr(dl) == intptr(dl, 0) == LLVM.Int32Type()
+ @test intptr(dl) == intptr(dl, 0) == LLVM.Int32Type()
- @test sizeof(dl, LLVM.Int32Type()) == storage_size(dl, LLVM.Int32Type()) == abi_size(dl, LLVM.Int32Type()) == 4
+ @test sizeof(dl, LLVM.Int32Type()) == storage_size(dl, LLVM.Int32Type()) == abi_size(dl, LLVM.Int32Type()) == 4
- @test abi_alignment(dl, LLVM.Int32Type()) == frame_alignment(dl, LLVM.Int32Type()) == preferred_alignment(dl, LLVM.Int32Type()) == 4
+ @test abi_alignment(dl, LLVM.Int32Type()) == frame_alignment(dl, LLVM.Int32Type()) == preferred_alignment(dl, LLVM.Int32Type()) == 4
@dispose mod=LLVM.Module("SomeModule") begin
gv = GlobalVariable(mod, LLVM.Int32Type(), "SomeGlobal")
- @test preferred_alignment(dl, gv) == 4
+ @test preferred_alignment(dl, gv) == 4
- datalayout!(mod, dl)
- @test string(datalayout(mod)) == string(dl)
+ datalayout!(mod, dl)
+ @test string(datalayout(mod)) == string(dl)
end
elem = [LLVM.Int32Type(), LLVM.FloatType()]
let st = LLVM.StructType(elem)
- @test element_at(dl, st, 4) == 1
- @test offsetof(dl, st, 1) == 4
- end
+ @test element_at(dl, st, 4) == 1
+ @test offsetof(dl, st, 1) == 4
+ end
- @test globals_addrspace(dl) == 0
- @dispose dl2=DataLayout(dlstr*"-G1") begin
- @test globals_addrspace(dl2) == 1
+ @test globals_addrspace(dl) == 0
+ @dispose dl2 = DataLayout(dlstr * "-G1") begin
+ @test globals_addrspace(dl2) == 1
end
end
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ ❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## master #516 +/- ##
=======================================
Coverage 87.88% 87.89%
=======================================
Files 45 45
Lines 2700 2701 +1
=======================================
+ Hits 2373 2374 +1
Misses 327 327
🚀 New features to boost your workflow:
|
vchuravy
approved these changes
Jun 16, 2025
0974438
to
764cc59
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cc @vchuravy