Home > Enterprise >  Understanding GCC's un-optimized assembly for UB n = n n - why increment twice before shi
Understanding GCC's un-optimized assembly for UB n = n n - why increment twice before shi

Time:12-16

I understand this is undefined behaviour and no one actually writes code like this. However I'm curious as to what the compiler would do to this piece of code.

int n = 3;
n =   n     n;

I compiled using both clang and gcc for comparison. Without optimizations. Here's the assembly generated from clang :

# clang -O0
movl    $3, -4(%rbp)
movl    -4(%rbp),            
  • Related