Open AaronBallman opened 2 months ago
@llvm/issue-subscribers-clang-frontend
Author: Aaron Ballman (AaronBallman)
@llvm/issue-subscribers-c11
Author: Aaron Ballman (AaronBallman)
I think we do the "proper" MaterializeTemporaryExpr thing for C++, but for C we just kind of guess what temporaries we need in CodeGen. I think this dates back to the initial implementation of C++ codegen. It would probably simplify CodeGen significantly if we could rely on the existence of an MaterializeTemporaryExpr where appropriate.
While investigating whether Clang properly implements WG14 N1285 (the factored approach), I found that Clang does not correctly materialize a temporary for the code that changed behavior:
https://godbolt.org/z/6q6bsabsj
In C11, that is an invalid use of a materialized temporary; in C99 it was required to work. Clang does not attempt to form a materialized temporary because of the language version check in: https://github.com/llvm/llvm-project/blob/c1bde0a2cb640b3607e9568b9a57b292e1f82666/clang/lib/Sema/SemaInit.cpp#L8667
Changing this to also materialize the temporary in C11 and later causes failed assertions in CodeGen:
so additional work is required to teach CodeGen how to handle the AST pattern. Alternatively, if this is undefined behavior we wish to define for our implementation, we should document it in the language extensions manual explicitly.