Pārlūkot izejas kodu

Add a test for recursion in structure members failing validation (#1983)

We normally check for recursion from the entry point in hlsl::DiagnoseTranslationUnit, at the end of AST parsing, but we can't do that when we compile for library targets because we have no entry point. This adds a test that we still fail validation.
Tristan Labelle 6 gadi atpakaļ
vecāks
revīzija
ebe3536a2a

+ 21 - 0
tools/clang/test/CodeGenHLSL/declarations/functions/recursion/lib_struct_member_unconditional.hlsl

@@ -0,0 +1,21 @@
+// RUN: %dxc -T lib_6_3 -exports main %s | FileCheck %s
+
+// Regression test for GitHub #1943, where recursive struct member functions
+// would crash the compiler.
+
+// The SCCP pass replaces the recursive call with an undef value,
+// which is why validation fails with a non-obvious error.
+
+// CHECK: validation errors
+// CHECK: Instructions should not read uninitialized value
+
+struct S
+{
+  int func() { return func(); }
+};
+
+int main() : OUT
+{
+  S s;
+  return s.func();
+}