llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.16k stars 12.03k forks source link

Broken .ll file makes clang segfault #60305

Open ychen306 opened 1 year ago

ychen306 commented 1 year ago

Here's a Godbolt link for reproducing the segfault. Here's the inlined (malformed) IR file.

@a = global i64 8 @b = global i64 8 @c = global i64 8 define i64 @d(i64 , i64 , i64 )                {                 br label %4   %.02 = phi i64 [ %.1, %12 ]   %.01 = phi i64 [ 5, %12 ]   %.0 = phi i64 [ 4, %12 ]   icmp ugt i64 %.01, 0   br i1 5, label %6, label %16   urem i64 %.01, 2   icmp eq i64 7, 1   br label %12   mul i64 %.02, %.0   %e = load i64, ptr @a%f = mul i64 0, %e   %g = load i64, ptr @b%n = ashr i64 %f, %g   %h = load i64, ptr @c%i = mul i64 %n, %h   sub i64 0, %i   br label %12   %.1 = phi i64 [ 1, %9 ]   mul i64 %.0, %.0   %j = load i64, ptr @a%k = mul i64 %14, %j   %l = load i64, ptr @b%o = ashr i64 %k, %l   %p = load i64, ptr @c%m = mul i64 %o, %p   sub i64 4, %m   udiv i64 %.01, 2   br label %4ret i64 %.02 }

You can crash clang with

clang -O3 bad.ll -c
efriedma-quic commented 1 year ago

Looks like the verifier rejects that IR. I guess clang somehow isn't running the verifier on IR inputs?