llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Clang-19.0 : Hang Issue with LLVM: No Output or Error Message involving recursive macros within a function

Open iamanonymouscs opened this issue 2 years ago • 2 comments

Description

I encountered an issue where the compiler hangs indefinitely while trying to compile a specific piece of code involving recursive macros within a function(https://godbolt.org/z/q6Gaz3c8r). The code snippet is provided below.GCC also has this problem(https://godbolt.org/z/9Exof1rrW).

Command

clang code_0.c  -O3 -Wall -Wextra -fverbose-asm -fopt-info-vec-optimized -c  -o  code_0

Code

int a(int c) {
  if (c < 12345) {
#define A \
    { int d = c % 12345; \
      int e = c ^ d * 12345; \
      int f = c * d % e % 12345; \
      c = f; }
#define B A A A A A A
#define C B B B B B B
#define D C C C C C C
#define E D D D D D D
    E E E E E
  }
  return c;
}



Version

# clang -v
Ubuntu clang version 19.0.0 (++20240301064251+dd426fa5f931-1~exp1~20240301184412.1845)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Candidate multilib: .;@m64
Selected multilib: .;@m64

Output

Nothing (Waited for nearly 300 seconds.

iamanonymouscs avatar Jul 19 '24 12:07 iamanonymouscs

Waited for nearly 300 seconds.

Halting problem solved!

I can abolutely imagine it taking longer than that. But apart from that, can you just use clang -E to get the preprocessed sources without any compilation and check how long that takes?

tbaederr avatar Jul 19 '24 17:07 tbaederr

But apart from that, can you just use clang -E to get the preprocessed sources without any compilation and check how long that takes?

Very fast, almost finished as soon as I started compiling. Here is the result: test.tar.gz

iamanonymouscs avatar Jul 20 '24 10:07 iamanonymouscs