Skip to content

Instantly share code, notes, and snippets.

@dpzmick
Last active October 10, 2019 06:18
Show Gist options
  • Save dpzmick/5c78dbd103459c474d83c9b67a7ff397 to your computer and use it in GitHub Desktop.
Save dpzmick/5c78dbd103459c474d83c9b67a7ff397 to your computer and use it in GitHub Desktop.
get wrecked clang
#include <stdlib.h>
int test() {
int *x = NULL;
int y = rand();
int z = rand();
int v = 4;
if (z == 8) x = &v;
if (y != 4) __builtin_unreachable();
if (y != 4) abort();
if (!x) __builtin_unreachable();
if (!x) abort();
int p2 = __builtin_popcount(z) == 1;
if (p2) exit(0);
else exit(1);
}
.file "test.c"
.text
.p2align 4
.globl test
.type test, @function
test:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
call rand@PLT
call rand@PLT
xorl %edi, %edi
call exit@PLT
.cfi_endproc
.LFE11:
.size test, .-test
.ident "GCC: (GNU) 9.2.0"
.section .note.GNU-stack,"",@progbits
.text
.file "test.c"
.globl test # -- Begin function test
.p2align 4, 0x90
.type test,@function
test: # @test
.cfi_startproc
# %bb.0:
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset %rbx, -16
callq rand@PLT
movl %eax, %ebx
callq rand@PLT
cmpl $4, %ebx
jne .LBB0_3
# %bb.1:
cmpl $8, %eax
jne .LBB0_3
# %bb.2:
xorl %edi, %edi
callq exit@PLT
.LBB0_3:
callq abort@PLT
.Lfunc_end0:
.size test, .Lfunc_end0-test
.cfi_endproc
# -- End function
.ident "clang version 8.0.1 (tags/RELEASE_801/final)"
.section ".note.GNU-stack","",@progbits
.addrsig
> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto
Thread model: posix
gcc version 9.2.0 (GCC)
> clang -v
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
both compiled with ${CC} test.c -S -O3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment