[llvm-dev] Accessing global variables arrays result in inlined getelementptrs

Antonin Reitz via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 23 12:11:03 PDT 2019


Hello,

Using LLVM+clang to do some static analysis, I face some issues due to 
the fact that when manipulating arrays that are global variables, IR 
getelementptr instructions seem to be somehow inlined.

For example:

int a[256];
int main() {
     a[0] = 1;
}

gives as a result the following IR code (with clang+llvm 8, without any 
flag).

@a = common dso_local global [256 x i32] zeroinitializer, align 16

; Function Attrs: noinline nounwind optnone sspstrong uwtable
define dso_local i32 @main() #0 {
   store i32 1, i32* getelementptr inbounds ([256 x i32], [256 x i32]* 
@a, i64 0, i64 0), align 16
   ret i32 0
}

Hence two questions.
- What is the main reason behind this behavior?
- Is there a way to disable it (ideally while preserving optimisations 
disabled)?

Thank you in advance,
Antonin Reitz



More information about the llvm-dev mailing list