Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a crash on valid consteval code.
Not all constants are emitted within the context of a function, so use the module's ASTContext instead because 1) that's the same as the current function ASTContext, and 2) the module can never be null. Fixes PR50787.
- Loading branch information
1 parent
482c53f
commit 68157fe
Showing
2 changed files
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm -o - | FileCheck %s | ||
|
||
namespace PR50787 { | ||
// This code would previously cause a crash. | ||
extern int x_; | ||
consteval auto& X() { return x_; } | ||
constexpr auto& x1 = X(); | ||
auto x2 = X(); | ||
|
||
// CHECK: @_ZN7PR507872x_E = external global i32, align 4 | ||
// CHECK-NEXT: @_ZN7PR507872x1E = constant i32* @_ZN7PR507872x_E, align 8 | ||
// CHECK-NEXT: @_ZN7PR507872x2E = global i32* @_ZN7PR507872x_E, align 4 | ||
} | ||
|