[clang] Set FP options in Sema when instantiating CompoundStmt
authorSerge Pavlov <sepavloff@gmail.com>
Mon, 21 Aug 2023 05:20:37 +0000 (12:20 +0700)
committerTobias Hieta <tobias@hieta.se>
Fri, 25 Aug 2023 07:34:51 +0000 (09:34 +0200)
commitf1d5ea362577a8a1b5fafe775cf82a449daa3b07
tree2ffdcdb9c31c9373ea61a4953591939933512456
parentdcb7bcff276664c12e1eb05e19e3e845a76b7116
[clang] Set FP options in Sema when instantiating CompoundStmt

When an expression is instantiated, TreeTransform skips ImplicitCastExpr
nodes, assuming they are recreated when the instantiated expression is
built. It breaks functions that use non-default floating-point options,
because they are kept in these ImplicitCastExprs. In this case the
recreated ImplicitCastExpr takes FP options from the current Sema state
and not from AST node.

To fix this issue the FP options in Sema object are set when a compound
statement is cloned in TreeTransform.

This change fixes https://github.com/llvm/llvm-project/issues/64605
([Regression 16 -> 17] Template instantiation ignores FENV_ACCESS being
ON for both definition and instantiation).

Differential Revision: https://reviews.llvm.org/D158158

(cherry picked from commit 0baf85c331090fbe2d2b42214ed0664d55feb0b5)
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/template-64605.cpp [new file with mode: 0644]