[clang] 7b69eab - [C11] Correct global atomic pointer initialization from an integer constant
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 2 11:42:42 PDT 2023
Author: Aaron Ballman
Date: 2023-07-02T14:41:21-04:00
New Revision: 7b69eabdc18799e4a6c61b7ffff9b52d330c6ada
URL: https://github.com/llvm/llvm-project/commit/7b69eabdc18799e4a6c61b7ffff9b52d330c6ada
DIFF: https://github.com/llvm/llvm-project/commit/7b69eabdc18799e4a6c61b7ffff9b52d330c6ada.diff
LOG: [C11] Correct global atomic pointer initialization from an integer constant
This is a follow-up to 2e275e24355cb224981f9beb2b026a3169fc7232 and
1395cde24b3641e284bb1daae7d56c189a2635e3 which corrects a missed case:
initializing an _Atomic(T *) from a null pointer constant in the form
of the integer literal 0.
Fixes https://github.com/llvm/llvm-project/issues/63550
Differential Revision: https://reviews.llvm.org/D154284
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/atomic.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 777245f86bdff7..09466253778a90 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14896,6 +14896,8 @@ class AtomicExprEvaluator :
default:
return ExprEvaluatorBaseTy::VisitCastExpr(E);
case CK_NullToPointer:
+ VisitIgnoredValue(E->getSubExpr());
+ return ZeroInitialization(E);
case CK_NonAtomicToAtomic:
return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr())
: Evaluate(Result, Info, E->getSubExpr());
diff --git a/clang/test/CodeGen/atomic.c b/clang/test/CodeGen/atomic.c
index 69f06eedb7caa6..242ec41ae1727f 100644
--- a/clang/test/CodeGen/atomic.c
+++ b/clang/test/CodeGen/atomic.c
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
+// CHECK: @[[NONSTATIC_GLOB_POINTER_FROM_INT:.+]] = global ptr null
// CHECK: @[[GLOB_POINTER:.+]] = internal global ptr null
+// CHECK: @[[GLOB_POINTER_FROM_INT:.+]] = internal global ptr null
// CHECK: @[[GLOB_INT:.+]] = internal global i32 0
// CHECK: @[[GLOB_FLT:.+]] = internal global float {{[0e\+-\.]+}}, align
@@ -125,6 +127,8 @@ void addrspace(int __attribute__((address_space(256))) * P) {
// Ensure that global initialization of atomics is correct.
static _Atomic(int *) glob_pointer = (void *)0;
+static _Atomic(int *) glob_pointer_from_int = 0;
+_Atomic(int *) nonstatic_glob_pointer_from_int = 0LL;
static _Atomic int glob_int = 0;
static _Atomic float glob_flt = 0.0f;
@@ -132,6 +136,12 @@ void force_global_uses(void) {
(void)glob_pointer;
// CHECK: %[[LOCAL_INT:.+]] = load atomic i32, ptr @[[GLOB_POINTER]] seq_cst
// CHECK-NEXT: inttoptr i32 %[[LOCAL_INT]] to ptr
+ (void)glob_pointer_from_int;
+ // CHECK: %[[LOCAL_INT_2:.+]] = load atomic i32, ptr @[[GLOB_POINTER_FROM_INT]] seq_cst
+ // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_2]] to ptr
+ (void)nonstatic_glob_pointer_from_int;
+ // CHECK: %[[LOCAL_INT_3:.+]] = load atomic i32, ptr @[[NONSTATIC_GLOB_POINTER_FROM_INT]] seq_cst
+ // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_3]] to ptr
(void)glob_int;
// CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
(void)glob_flt;
More information about the cfe-commits
mailing list