Repository navigation
[DXIL] Avoid infinite loop / stack overflow on invalid instruction - #7048
Merged
Joshua Batista (bob80905) merged 2 commits intoJan 14, 2025
Merged
Conversation
Contributor
You can test this locally with the following command:git-clang-format --diff a8a4e98a2367080af683c48feedd7f7481a31a96 d5a7b5f3df4ffe8289fb1d808844afe753a57147 -- lib/Analysis/VectorUtils2.cppView the diff from clang-format here.diff --git a/lib/Analysis/VectorUtils2.cpp b/lib/Analysis/VectorUtils2.cpp
index b5f57e3b..97bae15a 100644
--- a/lib/Analysis/VectorUtils2.cpp
+++ b/lib/Analysis/VectorUtils2.cpp
@@ -42,7 +42,7 @@ llvm::Value *llvm::findScalarElement(llvm::Value *V, unsigned EltNo) {
if (EltNo == IIElt)
return III->getOperand(1);
-// Guard against infinite loop on malformed, unreachable IR.
+ // Guard against infinite loop on malformed, unreachable IR.
if (III == III->getOperand(0))
return nullptr;
|
Tex Riddell (tex3d)
approved these changes
Jan 13, 2025
Tex Riddell (tex3d)
left a comment
Contributor
There was a problem hiding this comment.
Looks good. I still worry about the root cause of a malformed insertelement instruction, but this is a good guard against the downstream effect.
Chris B (llvm-beanz)
approved these changes
Jan 14, 2025
Mxr (SjMxr233)
pushed a commit
to ShaderHelper/DirectXShaderCompiler
that referenced
this pull request
Jul 24, 2025
…icrosoft#7048) The simplify instruction pass has a function called `findScalarElement`. This function will possibly recurse infinitely into the first operand of the instruction that it is passed. If this instruction, for example, is `%2 = insertelement <2 x i32> %2, i32 %sub, i32 0` Then the pass will recurse into the first operand of the insertelement instruction, which is the same insertelement instruction, and so on. This PR prevents infinite recursion and stack overflow by bailing out of the function early if there is a detection of the same value in the first operand. Fixes microsoft#7034 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The simplify instruction pass has a function called
findScalarElement.This function will possibly recurse infinitely into the first operand of the instruction that it is passed. If this instruction, for example, is
%2 = insertelement <2 x i32> %2, i32 %sub, i32 0Then the pass will recurse into the first operand of the insertelement instruction, which is the same insertelement instruction, and so on. This PR prevents infinite recursion and stack overflow by bailing out of the function early if there is a detection of the same value in the first operand.
Fixes #7034