Skip to content

Conversation

@tbaederr
Copy link
Contributor

This depends on signed-ness.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 24, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

This depends on signed-ness.


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

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/IntegralAP.h (+10-2)
  • (modified) clang/test/AST/ByteCode/intap.cpp (+9)
diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h
index b8aa21038256c7..209b0af7da5f30 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -136,8 +136,16 @@ template <bool Signed> class IntegralAP final {
   APValue toAPValue(const ASTContext &) const { return APValue(toAPSInt()); }
 
   bool isZero() const { return V.isZero(); }
-  bool isPositive() const { return V.isNonNegative(); }
-  bool isNegative() const { return !V.isNonNegative(); }
+  bool isPositive() const {
+    if constexpr (Signed)
+      return V.isNonNegative();
+    return true;
+  }
+  bool isNegative() const {
+    if constexpr (Signed)
+      return !V.isNonNegative();
+    return false;
+  }
   bool isMin() const { return V.isMinValue(); }
   bool isMax() const { return V.isMaxValue(); }
   static constexpr bool isSigned() { return Signed; }
diff --git a/clang/test/AST/ByteCode/intap.cpp b/clang/test/AST/ByteCode/intap.cpp
index d4440124856915..d0ad641fe508cb 100644
--- a/clang/test/AST/ByteCode/intap.cpp
+++ b/clang/test/AST/ByteCode/intap.cpp
@@ -104,6 +104,15 @@ static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
                                     // ref-note {{evaluates to '170141183460469231731687303715884105727 == 0'}}
 static const __int128_t INT128_MIN = -INT128_MAX - 1;
 
+
+namespace PointerArithmeticOverflow {
+  int n;
+  constexpr int *p = (&n + 1) + (unsigned __int128)-1; // expected-error {{constant expression}} \
+                                                       // expected-note {{cannot refer to element 3402}} \
+                                                       // ref-error {{constant expression}} \
+                                                       // ref-note {{cannot refer to element 3402}}
+}
+
 namespace i128 {
 
   constexpr int128_t I128_1 = 12;

@tbaederr tbaederr merged commit c81d666 into llvm:main Aug 24, 2024
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 24, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building clang at step 10 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/4371

Here is the relevant piece of the build log for the reference:

Step 10 (Add check check-offload) failure: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/test_libc.cpp (866 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug47654.cpp (867 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/wtime.c (868 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug53727.cpp (869 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug50022.cpp (870 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu :: offloading/bug49021.cpp (871 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu :: offloading/std_complex_arithmetic.cpp (872 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/complex_reduction.cpp (873 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/bug49021.cpp (874 of 876)
PASS: libomptarget :: x86_64-pc-linux-gnu-LTO :: offloading/std_complex_arithmetic.cpp (875 of 876)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1232.221877

qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Sep 30, 2024
…4987ce388

Local branch amd-gfx 80a4987 Merged main:75ef95584d8867d0039a43bad0bd8e53f3293f67 into amd-gfx:600cb8c5e762
Remote branch main c81d666 [clang][bytecode] Fix IntegralAP::is{Positive,Negative} (llvm#105924)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants