[PATCH] D140868: [C] Make (c ? e1 : e2) noreturn only if both e1 and e2 are noreturn
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 2 20:41:29 PST 2023
MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, mizvekov, rjmccall.
Herald added a subscriber: StephenFan.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
In C mode, if e1 is noreturn but e2 isn't, `(c ? e1 : e2)` is
incorrectly noreturn and Clang codegen produces `unreachable` which may
lead to miscompiles (see [1] `gawk/support/dfa.c`).
This problem has been known since
8c6b56f39d967347f28dd9c93f1cffddf6d7e4cd (2010) or earlier.
Fix this by making the result type noreturn only if both e1 and e2 are
noreturn.
Fix https://github.com/llvm/llvm-project/issues/59792 [1]
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140868
Files:
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/attr-noreturn.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140868.485911.patch
Type: text/x-patch
Size: 5641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230103/ff7f001c/attachment.bin>
More information about the cfe-commits
mailing list