mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 12:06:10 +00:00

Consider the following code: ```c bool const inf = (1.0/0.0); ``` When trying to emit the initialiser of this variable in C23, we end up hitting a code path in codegen in `VarDecl::evaluateValueImpl()` where we check for `IsConstantInitialization && (Ctx.getLangOpts().CPlusPlus || Ctx.getLangOpts().C23)`, and if that is the case and we emitted any notes, constant evaluation fails, and as a result, codegen issues this error: ``` <source>:1:12: error: cannot compile this static initializer yet 1 | bool const inf = (1.0/0.0); | ``` As a fix, only fail in C23 mode if we’re initialising a `constexpr` variable. This fixes #84784.
7 lines
385 B
C
7 lines
385 B
C
// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
|
|
|
|
// Division by 0 here is an error iff the variable is 'constexpr'.
|
|
const _Bool inf1 = (1.0/0.0 == __builtin_inf());
|
|
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // expected-error {{must be initialized by a constant expression}} expected-note {{division by zero}}
|
|
constexpr _Bool inf3 = __builtin_inf() == __builtin_inf();
|