[PATCH] D154284: [C11] Correct global atomic pointer initialization from an integer constant
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 1 10:01:17 PDT 2023
aaron.ballman created this revision.
aaron.ballman added reviewers: efriedma, rjmccall.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.
This is a follow-up to 2e275e24355cb224981f9beb2b026a3169fc7232 <https://reviews.llvm.org/rG2e275e24355cb224981f9beb2b026a3169fc7232> and 1395cde24b3641e284bb1daae7d56c189a2635e3 <https://reviews.llvm.org/rG1395cde24b3641e284bb1daae7d56c189a2635e3> which corrects a missed case: initializing an `_Atomic(T *)` from a null pointer constant in the form of the integer literal `0`.
(Note: a release note is unnecessary for this change as it's correcting an issue introduced during this cycle.)
Fixes https://github.com/llvm/llvm-project/issues/63550
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154284
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/atomic.c
Index: clang/test/CodeGen/atomic.c
===================================================================
--- clang/test/CodeGen/atomic.c
+++ clang/test/CodeGen/atomic.c
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
// 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 +126,7 @@
// Ensure that global initialization of atomics is correct.
static _Atomic(int *) glob_pointer = (void *)0;
+static _Atomic(int *) glob_pointer_from_int = 0;
static _Atomic int glob_int = 0;
static _Atomic float glob_flt = 0.0f;
@@ -132,6 +134,9 @@
(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)glob_int;
// CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
(void)glob_flt;
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -14896,6 +14896,8 @@
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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154284.536536.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230701/1bb73506/attachment-0001.bin>
More information about the cfe-commits
mailing list