Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLMatrixLower: allow exceptions to propagate out #6710

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

dneto0
Copy link
Collaborator

@dneto0 dneto0 commented Jun 20, 2024

If an exception is thrown, don't block it in the TempOverloadPool destructor. Allow it to propagate out as a user-visible error.

Explicitly clear the TempOverloadPool before returning from the HLMatrixLowerPass::runOnModule. In the normal case, when no exception is thrown, that will still verify that all the overloads actually have been lowered, and will assert out if they aren't.

@dneto0 dneto0 requested a review from a team as a code owner June 20, 2024 16:19
@dneto0
Copy link
Collaborator Author

dneto0 commented Jun 20, 2024

cc: @amaiorano

dneto0 added a commit to dneto0/DirectXShaderCompiler that referenced this pull request Jun 20, 2024
…tdout

Add support for 'xfailcat' in RUN: commands.
It requires the prior command to fail, and also propagates
stdout and stderr.

This is useful for cases for parsing error messages, example

   // RUN: %dxc -T cs_6_0 will_fail.hlsl %s | xfailcat | FileCheck %s
   // CHECK: error: something blah blah

This is an alternativ to supporting 'not'.

Also, modify the test from microsoft#6710 to check the error message
Copy link
Collaborator

@amaiorano amaiorano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way that we can instead have an explicit report_fatal_error call for these error cases rather than failing because an exception is thrown due to a bad cast?

I hate DXC's reliance on exceptions, so it would be preferable to make the error explicit (even if report_fatal_error does just throw an exception in DXC).

@dneto0
Copy link
Collaborator Author

dneto0 commented Jun 21, 2024

Is there a way that we can instead have an explicit report_fatal_error call for these error cases rather than failing because an exception is thrown due to a bad cast?

I hate DXC's reliance on exceptions, so it would be preferable to make the error explicit (even if report_fatal_error does just throw an exception in DXC).

In this case it comes from a failed checked cast. There are over a dozen of them in that pass:

                 cast<FixedVectorType>(LoweredDstTy)->getNumElements(),
                 cast<FixedVectorType>(LoweredVec->getType())->getNumElements(),
      cast<FixedVectorType>(Result->getType())->getNumElements();
      cast<PointerType>(HLMatrixType::getLoweredType(Global->getType()));
      cast<PointerType>(HLMatrixType::getLoweredType(MatAlloca->getType()));
               cast<VectorType>(LoweredRhs->getType()),
  Constant *IdxVec = cast<Constant>(
      DXASSERT(cast<ConstantInt>(*GEP->idx_begin())->isZero(),
    DXASSERT(cast<FixedVectorType>(Result->getType())->getNumElements() ==
  DXASSERT(cast<VectorType>(LoweredLhs->getType()) &&
  Function *Func = cast<Function>(Module.getOrInsertFunction(MangledName, Ty));
    IRBuilder<> Builder(cast<Instruction>(Use.getUser()));
  return cast<Constant>(MatTy.emitLoweredRegToMem(Vec, DummyBuilder));
  VectorType *IdxVecTy = cast<VectorType>(IdxVec->getType());
  VectorType *VecTy = cast<VectorType>(LoweredVal->getType());

I don't know which one is triggered for the given test case.

Do you mean something like rewriting the code to use dyn_cast and then explicitly handle the null return case? So the error is in apparent from the code?

The exception is thrown from https://github.com/microsoft/DirectXShaderCompiler/blame/b197bec653c11d50103c6971a9ccde7fa3cacc93/lib/Support/ErrorHandling.cpp#L143
I noticed @pow2clk changed the policy around checked casts, to make them throw hlsl exceptions. See 6b44d61

If an exception is thrown, don't block it in the TempOverloadPool
destructor. Allow it to propagate out as a user-visible error.

Explicitly clear the TempOverloadPool before returning from the
HLMatrixLowerPass::runOnModule. In the normal case, when
no exception is thrown, that will still verify that all the
overloads actually have been lowered, and will assert out
if they aren't.
It needs to be in the Clang tree because it uses dxopt.

Add a TODO in the test pointing at the bug for the permanent fix.
@dneto0
Copy link
Collaborator Author

dneto0 commented Jun 26, 2024

I rebased, and moved the test so it's lit-based and uses dxopt.

@dneto0 dneto0 merged commit 206133c into microsoft:main Jun 26, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants