Skip to content

Implement P2280R4 Using unknown pointers and references in constant expressions #63139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cor3ntin opened this issue Jun 6, 2023 · 3 comments · Fixed by #95474
Closed

Implement P2280R4 Using unknown pointers and references in constant expressions #63139

cor3ntin opened this issue Jun 6, 2023 · 3 comments · Fixed by #95474
Assignees
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@cor3ntin
Copy link
Contributor

cor3ntin commented Jun 6, 2023

No description provided.

@cor3ntin cor3ntin added clang:frontend Language frontend issues, e.g. anything involving "Sema" c++23 labels Jun 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2023

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2023

@llvm/issue-subscribers-c-2b

@KyunLFA
Copy link

KyunLFA commented Apr 6, 2024

Valve's Gamescope on git HEAD does not build anymore due to this error if my (limited) understanding is correct.

GCC passes, Clang doesn't.

FAILED: src/gamescope.p/wayland_backend.cpp.o 
/usr/bin/clang++ -Isrc/gamescope.p -Isrc -I../gamescope/src -I../gamescope/src/reshade/source -I../gamescope/src/reshade/include -I../gamescope/thirdparty/SPIRV-Headers/include/spirv/unified1 -Isubprojects/glm -I../gamescope/subprojects/glm -Isubprojects/reshade -I../gamescope/subprojects/reshade -Isubprojects/wlroots/include -I../gamescope/subprojects/wlroots/include -I../gamescope/subprojects/libdisplay-info/include -I../gamescope/subprojects/libliftoff/include -Isubprojects/stb -I../gamescope/subprojects/stb -Iprotocol -I/usr/include/libdrm -I/usr/include/SDL2 -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2 -I/usr/include/openvr -I/usr/include/libdecor-0 -fdiagnostics-color=always -D_GLIBCXX_ASSERTIONS=1 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c++20 -DWLR_USE_UNSTABLE -Wno-unused-parameter -Wno-missing-field-initializers -Wno-c99-designator -Wno-invalid-offsetof -Wno-unused-const-variable -Wno-deprecated-volatile -Wno-ignored-qualifiers -Wno-missing-braces -ffast-math -DHAVE_PIPEWIRE=1 -DHAVE_OPENVR=1 '-DHWDATA_PNP_IDS="//usr/share/hwdata/pnp.ids"' -flto=full -march=znver4 -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-protector-all -fcf-protection -fno-semantic-interposition -Wno-unused-command-line-argument -mllvm -polly -fwhole-program-vtables -Wp,-D_GLIBCXX_ASSERTIONS -fPIE -DAVIF_DLL -isystem/usr/include/libdrm -D_REENTRANT -pthread -DHAVE_DRM=1 -DHAVE_SDL2=1 -DHAVE_AVIF=1 -DHAVE_LIBCAP=1 -MD -MQ src/gamescope.p/wayland_backend.cpp.o -MF src/gamescope.p/wayland_backend.cpp.o.d -o src/gamescope.p/wayland_backend.cpp.o -c ../gamescope/src/wayland_backend.cpp
In file included from ../gamescope/src/wayland_backend.cpp:1:
In file included from ../gamescope/src/backend.h:7:
../gamescope/src/rc.h:171:36: error: constexpr if condition is not a constant expression
  171 |                     if constexpr ( m_pObject->ReferenceOwnsObject() )
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gamescope/src/rc.h:140:19: note: in instantiation of member function 'gamescope::Rc<gamescope::CWaylandFb>::DecRef' requested here
  140 |             this->DecRef();
      |                   ^
../gamescope/src/wayland_backend.cpp:1111:22: note: in instantiation of member function 'gamescope::Rc<gamescope::CWaylandFb>::~Rc' requested here
 1111 |     CWaylandBackend::CWaylandBackend()
      |                      ^
../gamescope/src/rc.h:171:36: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
  171 |                     if constexpr ( m_pObject->ReferenceOwnsObject() )
      |                                    ^
../gamescope/src/rc.h:171:36: error: constexpr if condition is not a constant expression
  171 |                     if constexpr ( m_pObject->ReferenceOwnsObject() )
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gamescope/src/rc.h:140:19: note: in instantiation of member function 'gamescope::Rc<gamescope::IBackendFb>::DecRef' requested here
  140 |             this->DecRef();
      |                   ^
../gamescope/src/wayland_backend.cpp:1231:69: note: in instantiation of member function 'gamescope::Rc<gamescope::IBackendFb>::~Rc' requested here
 1231 |             m_BlackFb = static_cast<CWaylandFb *>( m_pBlackTexture->GetBackendFb().get() );
      |                                                                     ^
../gamescope/src/rc.h:171:36: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
  171 |                     if constexpr ( m_pObject->ReferenceOwnsObject() )
      |                                    ^
2 errors generated.

Full context: https://github.com/ValveSoftware/gamescope/blob/master/src/rc.h

Tested on CachyOS (Arch) Linux, LLVM 19.0.0 1c683eb. (Workaround suggestions (besides switching compilers) appreciated)

shafik added a commit to shafik/llvm-project that referenced this issue Jul 17, 2024
…nstant expressions

P2280R4 allows the use of references in pointers of unknown origins in a
constant expression context but only in specific cases that could be constant
expressions.

We track whether a variable is a constexpr unknown in a constant expression by
setting a flag in either APValue or LValue and using this flag to prevent using
unknown values in places where it is not allowed.

In `evaluateVarDeclInit` we may need to create a new `APValue` to track the
unknown referene or pointer and we track that `APValue` in the
`CallStackFrame`.

Fixes: llvm#63139
llvm#63117
jktjkt added a commit to CESNET/velia that referenced this issue Nov 19, 2024
On one board, the 3V3 channel was constantly measuring 3.406V. This was
below our threshold, so I tried to identify what the actual standard
tolerances are. In the ATX specification version 2.2 [1] (unofficial
link because the official (?) formfactors.org now redirects to an Intel
page which says nope, nothing here), all tolerances for positive
voltages are specified as ±5%.

Let's use that for the warning threshold everywhere (because this is a
standard, anything that's within the allowed range is by definition OK).

We also have to account for the tolerance of the actual measurement. The
PSU's specification says [2, page 27] that (during our typical load,
which fits into the 10%-20% range), the measurements have a ±5%
tolerance. So it's "possible" that we have, say, a perfectly valid
voltage of 5.25V (which is within 5% of the 5V target) measured by an
inaccurate sensor, yielding a 5.5125V. This shall be our "critical"
threshold.

Let's wrap this in a shiny function as Tomas suggested. I also wanted to
add something like:

 static_assert(nominal > hysteresis * 10, "these units look very suspicious");

...but clang rejects this, probably due to [3].

TL;DR: a critical voltage alarm now means that the power is seriously
hosed. A warning might still be a false positive when the tolerances are
not aligned properly.

[1] https://cdn.instructables.com/ORIG/FS8/5ILB/GU59Z1AT/FS85ILBGU59Z1AT.pdf
[2] CzechLight/hw-docs, components/power/YH5151-1EB01R-Spec.pdf
[3] llvm/llvm-project#63139

Change-Id: Iad2e06ede62d82b5b338e8486224d85850d7c018
github-actions bot pushed a commit to arm/arm-toolchain that referenced this issue Jan 22, 2025
…ences in constant expressions (#95474)

P2280R4 allows the use of references in pointers of unknown origins in a
constant expression context but only in specific cases that could be
constant expressions.

We track whether a variable is a constexpr unknown in a constant
expression by setting a flag in either APValue or LValue and using this
flag to prevent using unknown values in places where it is not allowed.

Fixes: llvm/llvm-project#63139 llvm/llvm-project#63117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
4 participants