[clang] [clang] Fix crash in code with StmtExpr and atomic char load in Expr::EvaluateAsRValue. (PR #106751)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 30 08:40:52 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (c8ef)
<details>
<summary>Changes</summary>
Fixes #<!-- -->106576.
In the `IntExprEvaluator::VisitCastExpr` function, we handle `CK_NonAtomicToAtomic` in the same way as `CK_AtomicToNonAtomic`. This resolves the issue of converting non-atomic to atomic for integral values and prevents crashes when assertions are enabled.
---
Full diff: https://github.com/llvm/llvm-project/pull/106751.diff
2 Files Affected:
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1)
- (added) clang/test/AST/atomic-expr.c (+10)
``````````diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e8a4d1d3c74102..0571771e2a7e7d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14458,7 +14458,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
case CK_IntegralComplexToFloatingComplex:
case CK_BuiltinFnToFnPtr:
case CK_ZeroToOCLOpaqueType:
- case CK_NonAtomicToAtomic:
case CK_AddressSpaceConversion:
case CK_IntToOCLSampler:
case CK_FloatingToFixedPoint:
@@ -14482,6 +14481,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
case CK_UserDefinedConversion:
case CK_LValueToRValue:
case CK_AtomicToNonAtomic:
+ case CK_NonAtomicToAtomic:
case CK_NoOp:
case CK_LValueToRValueBitCast:
case CK_HLSLArrayRValue:
diff --git a/clang/test/AST/atomic-expr.c b/clang/test/AST/atomic-expr.c
new file mode 100644
index 00000000000000..0826a6491e8a6a
--- /dev/null
+++ b/clang/test/AST/atomic-expr.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+typedef _Atomic char atomic_char;
+
+atomic_char counter;
+
+char load_plus_one() {
+ return ({ counter; }) + 1;
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/106751
More information about the cfe-commits
mailing list