[PATCH] D152818: [Clang] Fix assertion when pragma FENV_ACCESS is used with a throw function.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 13 10:27:37 PDT 2023


aaron.ballman added reviewers: rjmccall, efriedma.
aaron.ballman added a comment.

In D152818#4417704 <https://reviews.llvm.org/D152818#4417704>, @zahiraam wrote:

> In D152818#4417683 <https://reviews.llvm.org/D152818#4417683>, @tbaeder wrote:
>
>> In D152818#4417649 <https://reviews.llvm.org/D152818#4417649>, @zahiraam wrote:
>>
>>> In D152818#4417644 <https://reviews.llvm.org/D152818#4417644>, @tbaeder wrote:
>>>
>>>> Has the test case been obfuscated on purpose?
>>>
>>> This is a smaller reproducible from creduce. Didn't know if it would be OK to have an include in a LIT test?
>>
>> Okay, not sure if we have a policy regarding that. Just looking at it, I don't think anyone understands what it's doing.
>
> It's definitely related to the use of the pragma and the throw function. I could put the "fstream" header in an Inputs folder? I see an #include <stdio.h> in Analysis/z3/Inputs/MockZ3_solver_check.c.

No, we don't want to include actual STL header content in the lit tests (we will mock up interfaces as needed, but they're usually uninteresting). It's worth noting that the original test case in your godbolt link has a quite different stack trace than your reduced example (they still end up in the same function though), so are there two different bugs? https://godbolt.org/z/Yaf5185cE

I spent some time reducing the test case down to:

  void g(const char *);
  
  template <class>
  struct q {
    static void r() { g(""); }
  };
  
  #pragma STDC FENV_ACCESS ON
  void a() { q<int>::r(); }

so there's nothing to do with `throw` expressions as the summary says. As best I can tell, this has something to do with template instantiation (making `q` no longer a template or calling `g()` directly both cause the issue to go away). I'd like to know a bit more about why the changes to the assertion are correct.



================
Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:161-164
   assert((CGF.CurFuncDecl == nullptr || CGF.Builder.getIsFPConstrained() ||
           isa<CXXConstructorDecl>(CGF.CurFuncDecl) ||
           isa<CXXDestructorDecl>(CGF.CurFuncDecl) ||
+          isa<FunctionDecl>(CGF.CurFuncDecl) ||
----------------
Constructors and destructors are function declarations, so those no longer need an explicit check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152818/new/

https://reviews.llvm.org/D152818



More information about the cfe-commits mailing list