Ver Fonte

Fix crash in Sema::CheckDerivedToBaseConversion when Paths is empty. (#3327)

Xiang Li há 4 anos atrás
pai
commit
2903170ac5

+ 6 - 3
tools/clang/lib/Sema/SemaDeclCXX.cpp

@@ -1783,10 +1783,13 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
   // explore multiple paths to determine if there is an ambiguity.
   // explore multiple paths to determine if there is an ambiguity.
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
                      /*DetectVirtual=*/false);
                      /*DetectVirtual=*/false);
+
   bool DerivationOkay = IsDerivedFrom(Derived, Base, Paths);
   bool DerivationOkay = IsDerivedFrom(Derived, Base, Paths);
-  assert(DerivationOkay &&
-         "Can only be used with a derived-to-base conversion");
-  (void)DerivationOkay;
+  // HLSL Change Begin - fix crash when Paths is empty.
+  // Merged from upstream.
+  if (!DerivationOkay)
+    return true;
+  // HLSL Change End.
   
   
   if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType())) {
   if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType())) {
     if (InaccessibleBaseID) {
     if (InaccessibleBaseID) {

+ 20 - 0
tools/clang/test/HLSLFileCheck/hlsl/diagnostics/errors/undef_field_recover.hlsl

@@ -0,0 +1,20 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// Make sure not crash.
+// CHECK:error: no member named 'AutoToStat' in 'S'
+
+struct S
+{
+ float AutoToStatic;
+ float b;
+};
+
+ConstantBuffer<S> s;
+
+float foo(float a, float b) {
+  return a + b;
+}
+
+float main() : SV_Target {
+  return foo(s.AutoToStatic, s.AutoToStat);
+}