This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix delayed template parsing
ClosedPublic

Authored by sepavloff on Jul 15 2023, 12:34 PM.

Details

Summary

Commit 98390ccb80569e8fbb20e6c996b4b8cff87fbec6 fixed late template
instantiation by clearing FP pragma stack before instantiation. This
solution was based on the assumptions:

  • FP pragma stack is not used anymore and it is safe to clear it,
  • Default FP options are determined by command line options.

Both the assumptions are wrong. When compilation produces precompiled
header file, state of the stack is serialized and then restored when the
precompiled header is used. Delayed template parsing occurs at the end
of translation unit but before serialization, so clearing FP pragma
stack effects serialized representation. When the precompiled file is
loaded, some conditions can be broken and clang crashed, it was
described in https://github.com/llvm/llvm-project/issues/63704. The
crash was observed only in few cases, on most buildbots it was absent.

The violation of expected conditions was caused by violation of the
second assumption. FPEvalMethod can be modified by target, so it is not
possible to deduce it from LangOptions only. So default FP state read
from precompiled header was different from the state in the initialized
Sema, and this was the crash reason.

Only two targets do such modification of default FP options, these are
i386 and AIX. so the problem was hard to reproduce.

Delayed template parsing should occur with empty pragma stack, so it
must be cleared before the instantiation, but the stack now is saved
and restored after the instantiation is done.

This change should fix https://github.com/llvm/llvm-project/issues/63704.

Diff Detail

Event Timeline

sepavloff created this revision.Jul 15 2023, 12:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2023, 12:34 PM
sepavloff requested review of this revision.Jul 15 2023, 12:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2023, 12:34 PM

Use calculated default FP options

sepavloff edited the summary of this revision. (Show Details)Jul 16 2023, 12:55 AM
mgorny accepted this revision.Jul 16 2023, 6:57 AM

Thanks. I can confirm that the tests pass for me with this applied.

This revision is now accepted and ready to land.Jul 16 2023, 6:57 AM

Fix clang-format errors

This revision was automatically updated to reflect the committed changes.