llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Calling Integral::getPtr() shouldn't happen for AddrLabelDiff integrals.

---
Full diff: https://github.com/llvm/llvm-project/pull/200393.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+6) 
- (modified) clang/test/AST/ByteCode/c.c (+8) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index a255a1fdf6f16..9300df85661dd 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -361,12 +361,18 @@ static bool AddSubNonNumber(InterpState &S, CodePtr OpPC, 
T LHS, T RHS) {
   typename T::ReprT Offset;
   IntegralKind Kind;
   if (LHS.isNumber()) {
+    if (RHS.getKind() == IntegralKind::AddrLabelDiff)
+      return Invalid(S, OpPC);
+
     Number = static_cast<typename T::ReprT>(LHS);
     Ptr = RHS.getPtr();
     Offset = RHS.getOffset();
     Kind = RHS.getKind();
   } else {
     assert(RHS.isNumber());
+    if (LHS.getKind() == IntegralKind::AddrLabelDiff)
+      return Invalid(S, OpPC);
+
     Number = static_cast<typename T::ReprT>(RHS);
     Ptr = LHS.getPtr();
     Offset = LHS.getOffset();
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index e82336e9731ba..4c39299db5ffa 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -466,3 +466,11 @@ void evaluatevalue(void) {
   const struct Oops s = {0, 0.};
   *(int *)(&s.a) = 42; // all-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
 }
+
+void AddrLabelDiffSub(void) {
+  _Static_assert((long)&&bar - (long)&&baz - 42 == foo, ""); // all-warning 
{{comparison between pointer and integer ('long' and 'int (*)()')}} \
+                                                             // all-error 
{{not an integral constant expression}} \
+                                                             // all-error 
{{use of undeclared label 'bar'}} \
+                                                             // all-error 
{{use of undeclared label 'baz'}} \
+                                                             // 
pedantic-warning 2{{use of GNU address-of-label extension}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/200393
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to