aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-08 16:43:54 +0300
committerGitHub <noreply@github.com>2022-09-08 16:43:54 +0300
commit6a62a15ecde10300f6281e2d49fed34031d5f68a (patch)
treed0c5e7abd7ef2a1bc2b1d4ee283354f1da25322b /src/codegen
parenta7661f115dccf26b141557c923171f325cdc2757 (diff)
parentc7e45aebafef0372fe231816eeffd18198240f14 (diff)
downloadzig-6a62a15ecde10300f6281e2d49fed34031d5f68a.tar.gz
zig-6a62a15ecde10300f6281e2d49fed34031d5f68a.zip
Merge pull request #12773 from Vexu/stage2-fixes
Sema: fix UAF in zirClosureGet
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 80ffd7a665..043f0bbdc7 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -9204,6 +9204,12 @@ pub const FuncGen = struct {
return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
}
+ if (info.pointee_type.isPtrAtRuntime()) {
+ const same_size_int = self.context.intType(elem_bits);
+ const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
+ return self.builder.buildIntToPtr(truncated_int, elem_llvm_ty, "");
+ }
+
return self.builder.buildTrunc(shifted_value, elem_llvm_ty, "");
}
@@ -9235,7 +9241,10 @@ pub const FuncGen = struct {
// Convert to equally-sized integer type in order to perform the bit
// operations on the value to store
const value_bits_type = self.context.intType(elem_bits);
- const value_bits = self.builder.buildBitCast(elem, value_bits_type, "");
+ const value_bits = if (elem_ty.isPtrAtRuntime())
+ self.builder.buildPtrToInt(elem, value_bits_type, "")
+ else
+ self.builder.buildBitCast(elem, value_bits_type, "");
var mask_val = value_bits_type.constAllOnes();
mask_val = mask_val.constZExt(containing_int_ty);