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

[DXIL] Avoid infinite loop / stack overflow on invalid instruction #7048

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bob80905
Copy link
Collaborator

@bob80905 bob80905 commented Jan 6, 2025

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 #7034

@bob80905 bob80905 requested a review from a team as a code owner January 6, 2025 21:04
Copy link
Contributor

github-actions bot commented Jan 6, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff a8a4e98a2367080af683c48feedd7f7481a31a96 d5a7b5f3df4ffe8289fb1d808844afe753a57147 -- lib/Analysis/VectorUtils2.cpp
View 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;
 
  • Check this box to apply formatting changes to this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

Stack overflow when compiling for cs_6_6
1 participant