-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Open
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The error is:
clang++ -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall -fPIC -I/home/tcaswell/.virtualenvs/cp315-clang/include -I/home/tcaswell/.pybuild/cp315-clang/include/python3.15 -c src/greenlet/greenlet.cpp -o build/temp.linux-x86_64-cpython-315/src/greenlet/greenlet.o
In file included from src/greenlet/greenlet.cpp:19:
In file included from src/greenlet/greenlet_internal.hpp:18:
In file included from src/greenlet/TGreenlet.hpp:35:
In file included from /home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_interpframe.h:8:
In file included from /home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_code.h:11:
/home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_backoff.h:65:30: error: non-constant-expression cannot be narrowed from type 'int' to 'uint16_t' (aka 'unsigned short') in initializer list [-Wc++11-narrowing]
65 | .value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_backoff.h:43:5: note: expanded from macro 'MAKE_VALUE_AND_BACKOFF'
43 | ((value << BACKOFF_BITS) | backoff)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_backoff.h:65:30: note: insert an explicit cast to silence this issue
65 | .value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| static_cast<uint16_t>( )
/home/tcaswell/.pybuild/cp315-clang/include/python3.15/internal/pycore_backoff.h:43:5: note: expanded from macro 'MAKE_VALUE_AND_BACKOFF'
43 | ((value << BACKOFF_BITS) | backoff)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/greenlet/greenlet.cpp:43:
src/greenlet/PyGreenlet.cpp:62:23: warning: unused variable 'c' [-Wunused-variable]
62 | UserGreenlet* c = new UserGreenlet(o, GET_THREAD_STATE().state().borrow_current());
| ^
1 warning and 1 error generated.
error: command '/lib/ccache/bin/clang++' failed with exit code 1
error: subprocess-exited-with-error
which was introduce via https://github.com/python/cpython/pull/141591/files#diff-2772c99555ca0a4a3987e20582200c6eb6314fea3e5f3a5f7f2cbc2e371e22adL51 which inlined tho computation of the new value with creating the struct to hold it:
cpython/Include/internal/pycore_backoff.h
Lines 59 to 67 in 726e8e8
| static inline _Py_BackoffCounter | |
| make_backoff_counter(uint16_t value, uint16_t backoff) | |
| { | |
| assert(backoff <= UNREACHABLE_BACKOFF); | |
| assert(value <= MAX_VALUE); | |
| return ((_Py_BackoffCounter){ | |
| .value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff) | |
| }); | |
| } |
This is apparently fine with clang's c complier and gcc/g++, but clang++ warns. I'm out of my c/++ depth to understand why.
The following patch fixes the issue:
diff --git a/Include/internal/pycore_backoff.h b/Include/internal/pycore_backoff.h
index 7f60eb49508..feb5f3e11e6 100644
--- a/Include/internal/pycore_backoff.h
+++ b/Include/internal/pycore_backoff.h
@@ -61,8 +61,9 @@ make_backoff_counter(uint16_t value, uint16_t backoff)
{
assert(backoff <= UNREACHABLE_BACKOFF);
assert(value <= MAX_VALUE);
+ uint16_t result = MAKE_VALUE_AND_BACKOFF(value, backoff);
return ((_Py_BackoffCounter){
- .value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff)
+ .value_and_backoff = result
});
}however I am not sure if this should be accounted for here of if greenlet should be working around it.
To reproduce this you may also need to account for python-greenlet/greenlet#481
@ clang++ --version
clang version 21.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
CPython versions tested on:
CPython main branch
Operating systems tested on:
linux (Arch)
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error