The relevant language rule from C11 is 6.5.16.1p1: "the left operand is an atomic, qualified, or unqualified pointer, and the right is a null pointer constant; or". We correctly handled qualified or unqualified pointer types, but failed to handle atomic-qualified pointer types. Now we look through the atomic qualification before testing the constraint requirements.
Details
- Reviewers
rsmith erichkeane - Group Reviewers
Restricted Project - Commits
- rG2e275e24355c: [C11] Allow initialization of an atomic-qualified pointer from a null pointer…
Diff Detail
Event Timeline
Added an additional test case (assignment of a null pointer constant to an atomic function pointer) that was mentioned in a comment on the original bug report).
Added a -pedantic run line and used (void *)0 as a null pointer constant for the last test.
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
10307 | Does the LHSType here need switching too? Or are we just going to use the 'normal' pointer conversion rules here? |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
10307 | The intent is to follow the normal conversion rules here -- this just allows us to check those rules properly when the LHS type is atomic as well as when it's non-atomic. |
We bisected a build failure on the emscripten waterfall to this change:
https://ci.chromium.org/ui/p/emscripten-releases/builders/try/linux/b8782932845295577777/overview
https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8782932845295577777/+/u/Build_Emscripten__upstream_/stdout
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libc-mt.a... (this will be cached in "/b/s/w/ir/x/w/install/emscripten/cache/sysroot/lib/wasm32-emscripten/libc-mt.a" for subsequent builds) /b/s/w/ir/x/w/install/emscripten/system/lib/pthread/emscripten_yield.c:10:26: error: cannot compile this static initializer yet static _Atomic pthread_t crashed_thread_id = NULL; ^ 1 error generated. emcc: error: '/b/s/w/ir/x/w/install/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_SHARED_MEMORY__=1 -D__EMSCRIPTEN_WASM_WORKERS__=1 -Werror=implicit-function-declaration --sysroot=/b/s/w/ir/x/w/install/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O2 -Wall -Werror -fno-unroll-loops -std=c99 -D_XOPEN_SOURCE=700 -Wno-unused-result -Os -fno-inline-functions -fno-builtin -Wno-ignored-attributes -Wno-macro-redefined -Wno-shift-op-parentheses -Wno-string-plus-int -Wno-missing-braces -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-label -Wno-pointer-sign -g3 -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc/musl/src/internal -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc/musl/src/include -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc -I/b/s/w/ir/x/w/install/emscripten/system/lib/pthread -pthread -DNDEBUG -ffile-prefix-map=/b/s/w/ir/x/w/install/emscripten=/emsdk/emscripten -fdebug-compilation-dir=/emsdk/emscripten -c -matomics -mbulk-memory /b/s/w/ir/x/w/install/emscripten/system/lib/pthread/emscripten_yield.c -o /b/s/w/ir/x/w/install/emscripten/cache/build/libc-mt-tmp/emscripten_yield.o' failed (returned 1) embuilder: error: Subprocess 11/1107 failed (returned 1)! (cmdline: /b/s/w/ir/x/w/install/emscripten/emcc -O2 -Wall -Werror -fno-unroll-loops -std=c99 -D_XOPEN_SOURCE=700 -Wno-unused-result -Os -fno-inline-functions -fno-builtin -Wno-ignored-attributes -Wno-macro-redefined -Wno-shift-op-parentheses -Wno-string-plus-int -Wno-missing-braces -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-label -Wno-pointer-sign -g -sSTRICT -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc/musl/src/internal -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc/musl/src/include -I/b/s/w/ir/x/w/install/emscripten/system/lib/libc -I/b/s/w/ir/x/w/install/emscripten/system/lib/pthread -pthread -sWASM_WORKERS -DNDEBUG -ffile-prefix-map=/b/s/w/ir/x/w/install/emscripten=/emsdk/emscripten -fdebug-compilation-dir=/emsdk/emscripten -c /b/s/w/ir/x/w/install/emscripten/system/lib/pthread/emscripten_yield.c -o /b/s/w/ir/x/w/install/emscripten/cache/build/libc-mt-tmp/emscripten_yield.o) Exception thrown in build step.
Prior to this change this code compiled fine.
We see the same compilation error as the one reported by @sbc100 in several other C libraries.
Here's a short reproducer: https://godbolt.org/z/Y8eds47na
The tests imply that this should work. Please revert.
Thank you (both) for reporting this issue so quickly! I believe I've addressed it with 1395cde24b3641e284bb1daae7d56c189a2635e3, but if you're still having problems after that commit, let me know and I'll revert both changes to investigate further.
@aaron.ballman your patch (1395cde24b3641e284bb1daae7d56c189a2635e3) fixed all issues we encountered. Thanks!!
Does the LHSType here need switching too? Or are we just going to use the 'normal' pointer conversion rules here?