[clang] [clang][bytecode] Remove unnecessary pointer type checks in CheckLoad/CheckStore (PR #224884)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 19 22:09:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Only check the pointer type once.
---
Full diff: https://github.com/llvm/llvm-project/pull/224884.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+24-18)
- (modified) clang/lib/AST/ByteCode/Pointer.h (+4-1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index ab6b474503a3b..1761b65afd911 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -729,7 +729,7 @@ bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr, AccessKinds AK) {
return false;
}
-static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+static bool CheckVolatile(InterpState &S, CodePtr OpPC, PtrView Ptr,
AccessKinds AK) {
assert(Ptr.isLive());
@@ -745,7 +745,7 @@ static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
// The reason why Ptr is volatile might be further up the hierarchy.
// Find that pointer.
- Pointer P = Ptr;
+ PtrView P = Ptr;
while (!P.isRoot()) {
if (P.getType().isVolatileQualified())
break;
@@ -960,15 +960,18 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return false;
if (!Ptr.isInitialized())
return diagnoseUninitialized(S, OpPC, Ptr, AK);
- if (!CheckLifetime(S, OpPC, Ptr, AK))
- return false;
- if (Ptr.isBlockPointer() && !CheckTemporary(S, OpPC, Ptr.block(), AK))
- return false;
- if (!CheckMutable(S, OpPC, Ptr))
- return false;
- if (!CheckVolatile(S, OpPC, Ptr, AK))
- return false;
+ if (Ptr.isBlockPointer()) {
+ if (!CheckLifetime(S, OpPC, Ptr.getLifetime(), Ptr.block(), AK))
+ return false;
+ if (!CheckTemporary(S, OpPC, Ptr.block(), AK))
+ return false;
+
+ if (!CheckMutable(S, OpPC, Ptr.view(), AK))
+ return false;
+ if (!CheckVolatile(S, OpPC, Ptr.view(), AK))
+ return false;
+ }
if (isConstexprUnknown(Ptr))
return false;
@@ -1022,14 +1025,17 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
if (!CheckActive(S, OpPC, Ptr, AK_Read))
return false;
- if (!CheckLifetime(S, OpPC, Ptr, AK_Read))
- return false;
if (!Ptr.isInitialized())
return diagnoseUninitialized(S, OpPC, Ptr, AK_Read);
- if (Ptr.isBlockPointer() && !CheckTemporary(S, OpPC, Ptr.block(), AK_Read))
- return false;
- if (!CheckMutable(S, OpPC, Ptr))
- return false;
+
+ if (Ptr.isBlockPointer()) {
+ if (!CheckLifetime(S, OpPC, Ptr.getLifetime(), Ptr.block(), AK_Read))
+ return false;
+ if (!CheckTemporary(S, OpPC, Ptr.block(), AK_Read))
+ return false;
+ if (!CheckMutable(S, OpPC, Ptr.view()))
+ return false;
+ }
if (Ptr.isConstexprUnknown())
return false;
return true;
@@ -1061,9 +1067,9 @@ bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return false;
if (!CheckConst(S, OpPC, Ptr))
return false;
- if (!CheckVolatile(S, OpPC, Ptr, AK))
+ if (!CheckVolatile(S, OpPC, Ptr.view(), AK))
return false;
- if (!CheckMutable(S, OpPC, Ptr, AK))
+ if (!CheckMutable(S, OpPC, Ptr.view(), AK))
return false;
if (isConstexprUnknown(Ptr))
return false;
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index d19374acf00c4..54e0f858b4fa0 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -49,6 +49,9 @@ struct PtrView {
bool isMutable() const {
return !isRoot() && getInlineDesc()->IsFieldMutable;
}
+ bool isVolatile() const {
+ return isRoot() ? getDeclDesc()->IsVolatile : getInlineDesc()->IsVolatile;
+ }
bool inUnion() const { return getInlineDesc()->InUnion; };
bool inArray() const { return getFieldDesc()->IsArray; }
bool inPrimitiveArray() const { return getFieldDesc()->isPrimitiveArray(); }
@@ -954,7 +957,7 @@ class Pointer {
bool isVolatile() const {
if (!isBlockPointer())
return false;
- return isRoot() ? getDeclDesc()->IsVolatile : getInlineDesc()->IsVolatile;
+ return view().isVolatile();
}
/// Returns the declaration ID.
``````````
</details>
https://github.com/llvm/llvm-project/pull/224884
More information about the cfe-commits
mailing list