[clang] [llvm] [llvm:ir] Add support for constant data exceeding 4GiB (PR #126481)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 02:55:45 PST 2025


================
@@ -644,7 +644,7 @@ class ConstantDataSequential : public ConstantData {
   Type *getElementType() const;
 
   /// Return the number of elements in the array or vector.
-  unsigned getNumElements() const;
+  uint64_t getNumElements() const;
----------------
pzzp wrote:

ok, I update `getElementAsInteger` and `getElementAsFloat`, it seems that these two are used in codegen.
I test it with this script's generation
```bash
#!/bin/bash
cat << EOF
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
EOF

# generate @ARR = global [1073741825 x i32] [...], align 16
for (( i = 0; i<1024; i++)); do
  ARR_1K+="i32 $((RANDOM % 97)), "
done
for (( i = 0; i<1024; i++)); do
  ARR_1M+="$ARR_1K"
done
echo -n "@ARR = global [$((1024 * 1024 * 1024 + 1)) x i32] ["
for (( i = 0; i<$((1024)); i++)); do
  echo -n "$ARR_1M"
done
echo -n 'i32 233], align 16'

cat << EOF
!llvm.module.flags = !{!0, !1, !2, !3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
EOF
```
I checked that the result is ok. The last number in result asm is `233` and the size  is `4294967300`

https://github.com/llvm/llvm-project/pull/126481


More information about the cfe-commits mailing list