[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-hip-vega20` running 
on `hip-vega20-0` while building `clang` at step 3 "annotate".

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


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

```
Step 3 (annotate) failure: 
'../llvm-zorg/zorg/buildbot/builders/annotated/hip-build.sh --jobs=' (failure)
...
[38/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 
-DNDEBUG  External/HIP/CMakeFiles/memmove-hip-6.0.2.dir/memmove.hip.o -o 
External/HIP/memmove-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 
--hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && 
/usr/local/bin/cmake -E create_symlink 
/buildbot/llvm-test-suite/External/HIP/memmove.reference_output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/memmove.reference_output-hip-6.0.2
[39/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 
-DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 
--offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 
--offload-arch=gfx1100 -xhip -mfma -MD -MT 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -MF 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d
 -o 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -c 
/buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
[40/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 
-DNDEBUG  
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -o External/HIP/TheNextWeek-hip-6.0.2  
--rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt 
-unwindlib=libgcc -frtlib-add-rpath && cd 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && 
/usr/local/bin/cmake -E create_symlink 
/buildbot/llvm-test-suite/External/HIP/TheNextWeek.reference_output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/TheNextWeek.reference_output-hip-6.0.2
+ build_step 'Testing HIP test-suite'
+ echo '@@@BUILD_STEP Testing HIP test-suite@@@'
+ ninja -v check-hip-simple
@@@BUILD_STEP Testing HIP test-suite@@@
[0/1] cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP 
&& /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/llvm-lit -sv 
empty-hip-6.0.2.test with-fopenmp-hip-6.0.2.test saxpy-hip-6.0.2.test 
memmove-hip-6.0.2.test InOneWeekend-hip-6.0.2.test TheNextWeek-hip-6.0.2.test 
blender.test
-- Testing: 7 tests, 7 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80
FAIL: test-suite :: External/HIP/blender.test (7 of 7)
 TEST 'test-suite :: External/HIP/blender.test' FAILED 


/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/timeit-target 
--timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 
--limit-rss-size 838860800 --append-exitstatus --redirect-output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.out
 --redirect-input /dev/null --summary 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.time
 /bin/bash test_blender.sh
/bin/bash verify_blender.sh 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.out
Begin Blender test.
TEST_SUITE_HIP_ROOT=/buildbot/Externals/hip
Render /buildbot/Externals/hip/Blender_Scenes/290skydemo_release.blend
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_card_inum 
returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_concat returned 
error: No such file or directory
ALSA lib confmisc.c:1334:(snd_func_refer) error evaluating name
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_refer returned 
error: No such file or directory
ALSA lib conf.c:5701:(snd_config_expand) Evaluate error: No such file or 
directory
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM default
Blender 4.1.1 (hash e1743a0317bc built 2024-04-15 23:47:45)
Read blend: "/buildbot/Externals/hip/Blender_Scenes/290skydemo_release.blend"
Could not open as Ogawa file from provided streams.
Unable to open /buildbot/Externals/hip/Blender_Scenes/290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.002", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.003

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/93046

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/5] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad0..4d9313f4c7ca57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c0..b7aae9395e6357 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..d5a47a071e2cd7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241c..ae7942aca39e63 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf9..f0c3c6dbdf97b0 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok there is a test failure!

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@cor3ntin Done!

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/93046

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/4] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad0..4d9313f4c7ca57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c0..b7aae9395e6357 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..d5a47a071e2cd7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241c..ae7942aca39e63 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf9..f0c3c6dbdf97b0 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok can you fix the conflicts and ping me so i can merge?

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-07-17 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/93046

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/3] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad..4d9313f4c7ca5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c..b7aae9395e635 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..d5a47a071e2cd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241..ae7942aca39e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf..f0c3c6dbdf97b 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify=expected %s

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-06-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr approved this pull request.

LGTM.

I guess we should close https://github.com/llvm/llvm-project/pull/89449 after 
merging this.

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/93046

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/2] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad..4d9313f4c7ca5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c..b7aae9395e635 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..d5a47a071e2cd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241..ae7942aca39e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf..f0c3c6dbdf97b 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify=expected 

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Vlad Serebrennikov via cfe-commits


@@ -18,6 +30,38 @@ void f(B b) {
 struct D : B {};
 } // namespace cwg2718
 
+namespace cwg2749 { // cwg2749: 19
+
+extern int x[2];
+struct Y {
+  int i;
+  int j;
+};
+extern Y y[2];
+
+#if __cplusplus >= 201103L
+static_assert(static_cast(x + 0) < static_cast(x + 1), "");
+static_assert(static_cast(&y[0].i) < static_cast(&y[0].j), "");
+static_assert(static_cast(&y[0].j) < static_cast(&y[1].i), "");
+#else
+enum X {
+  a = static_cast(x + 0) < static_cast(x + 1),

Endilll wrote:

Feel free to remove the test in C++98 if it doesn't fit the requirements of 
integral constant expression, but for the future reference we also use the 
following in some DR tests: 
https://github.com/llvm/llvm-project/blob/0eb9e021b15f477b796a6aaed94c94887f19171c/clang/test/CXX/drs/cwg1xx.cpp#L13-L17

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Mital Ashok via cfe-commits


@@ -18,6 +30,38 @@ void f(B b) {
 struct D : B {};
 } // namespace cwg2718
 
+namespace cwg2749 { // cwg2749: 19
+
+extern int x[2];
+struct Y {
+  int i;
+  int j;
+};
+extern Y y[2];
+
+#if __cplusplus >= 201103L
+static_assert(static_cast(x + 0) < static_cast(x + 1), "");
+static_assert(static_cast(&y[0].i) < static_cast(&y[0].j), "");
+static_assert(static_cast(&y[0].j) < static_cast(&y[1].i), "");
+#else
+enum X {
+  a = static_cast(x + 0) < static_cast(x + 1),

MitalAshok wrote:

C++98 has a separate test because `_Static_assert` doesn't constant fold its 
arguments in C++ (only in C as an extension), and in C++98 ยง6.4 "Constant 
expressions" "an *integral constant expression* shall have integral type and 
shall only have operands that are integer constants, enumeration constants, 
character constants, `sizeof` expressions, and floating constants that are the 
immediate operands of cast", causing `static_assert((x + 0) < (x + 1))` to fail 
because it has address operands.

On second thought, this change only applies in C++98 when we do constant 
folding as an extension. I don't think we need to test that a now-non-existent 
warning isn't issued in C++98 mode when we use an extension, so I'll just get 
rid of the C++98 test

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Vlad Serebrennikov via cfe-commits


@@ -18,6 +30,38 @@ void f(B b) {
 struct D : B {};
 } // namespace cwg2718
 
+namespace cwg2749 { // cwg2749: 19
+
+extern int x[2];
+struct Y {
+  int i;
+  int j;
+};
+extern Y y[2];
+
+#if __cplusplus >= 201103L
+static_assert(static_cast(x + 0) < static_cast(x + 1), "");
+static_assert(static_cast(&y[0].i) < static_cast(&y[0].j), "");
+static_assert(static_cast(&y[0].j) < static_cast(&y[1].i), "");
+#else
+enum X {
+  a = static_cast(x + 0) < static_cast(x + 1),
+// expected-warning@-1 {{expression is not an integral constant expression; 
folding it to a constant is a GNU extension}}

Endilll wrote:

If you need constant folding in 98, you can use the following macro: 
https://github.com/llvm/llvm-project/blob/0eb9e021b15f477b796a6aaed94c94887f19171c/clang/test/CXX/drs/cwg1xx.cpp#L13-L17

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Vlad Serebrennikov via cfe-commits


@@ -1,11 +1,23 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify=expected %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -Wgnu-folding-constant 
-verify=expected %s

Endilll wrote:

I hope `-Wgnu-folding-constant` is not going to be needed after you apply other 
suggestions. Even if it's needed, this has to be handled some other way, not 
with an additional flag.

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Vlad Serebrennikov via cfe-commits


@@ -18,6 +30,38 @@ void f(B b) {
 struct D : B {};
 } // namespace cwg2718
 
+namespace cwg2749 { // cwg2749: 19
+
+extern int x[2];
+struct Y {
+  int i;
+  int j;
+};
+extern Y y[2];
+
+#if __cplusplus >= 201103L

Endilll wrote:

If you need to match diagnostics only in C++98, you should modify C++98 RUN 
line to say `-verify=expected,cxx98`, and then use directives like `// 
cxx98-error`.

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-30 Thread Vlad Serebrennikov via cfe-commits


@@ -18,6 +30,38 @@ void f(B b) {
 struct D : B {};
 } // namespace cwg2718
 
+namespace cwg2749 { // cwg2749: 19
+
+extern int x[2];
+struct Y {
+  int i;
+  int j;
+};
+extern Y y[2];
+
+#if __cplusplus >= 201103L
+static_assert(static_cast(x + 0) < static_cast(x + 1), "");
+static_assert(static_cast(&y[0].i) < static_cast(&y[0].j), "");
+static_assert(static_cast(&y[0].j) < static_cast(&y[1].i), "");
+#else
+enum X {
+  a = static_cast(x + 0) < static_cast(x + 1),

Endilll wrote:

You should copy over the C++98 "backport" of `static_assert` from e.g. (we use 
it liberally across DR test suite)
https://github.com/llvm/llvm-project/blob/0eb9e021b15f477b796a6aaed94c94887f19171c/clang/test/CXX/drs/cwg1xx.cpp#L8-L11

https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-22 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok edited 
https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-22 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/93046

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH] [Clang] CWG2749: relational operators involving pointers to
 void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad..4d9313f4c7ca5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c..b7aae9395e635 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..d5a47a071e2cd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241..ae7942aca39e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf..f0c3c6dbdf97b 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify=expected %s
+

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.

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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/Basic/DiagnosticASTKinds.td (-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (-10) 
- (modified) clang/test/AST/Interp/literals.cpp (+2-6) 
- (modified) clang/test/CXX/drs/cwg27xx.cpp (+45-1) 
- (modified) clang/test/CXX/expr/expr.const/p2-0x.cpp (+2-2) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad..4d9313f4c7ca5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c..b7aae9395e635 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..d5a47a071e2cd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241..ae7942aca39e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf..f0c3c6dbdf97b 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify=expected %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -Wgnu-folding-constant 
-verify=expected %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -verify=expected %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++14 -

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-05-22 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/93046

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.

>From aa5e7f71efdfcdea902ac881fd8db6b7c4f4538d Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH] [Clang] CWG2749: relational operators involving pointers to
 void

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  |  4 +-
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad..4d9313f4c7ca5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c..b7aae9395e635 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..d5a47a071e2cd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241..ae7942aca39e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf..f0c3c6dbdf97b 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RU