Selaa lähdekoodia

Only update decl when function has a body. (#2937)

Xiang Li 5 vuotta sitten
vanhempi
commit
4f936272ef

+ 10 - 0
tools/clang/test/HLSLFileCheck/rewriter/built-in.hlsl

@@ -0,0 +1,10 @@
+// RUN: %dxr -E main -remove-unused-globals %s | FileCheck %s
+
+// make sure build-in functions not crash.
+// CHECK:min
+
+float a;
+float b;
+float main() : SV_Target {
+  return min(a, b);
+}

+ 1 - 1
tools/clang/tools/libclang/dxcrewriteunused.cpp

@@ -109,7 +109,7 @@ public:
           m_pendingFunctions.push_back(fnDeclWithbody);
         }
       }
-      if (fnDeclWithbody != fnDecl) {
+      if (fnDeclWithbody && fnDeclWithbody != fnDecl) {
         // In case fnDecl is only a decl, setDecl to fnDeclWithbody.
         // fnDecl will be removed.
         ref->setDecl(fnDeclWithbody);