aco: fix printing ASM on GFX6-7 again
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 22 Jun 2020 11:33:21 +0000 (13:33 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 23 Jun 2020 07:45:03 +0000 (07:45 +0000)
Checking errno is actually wrong because it's only updated if
popen() fails (ie. NULL). One solution is to check if the first
line is empty.

Fixes: c95d258d1bc ("aco: fix printing ASM on GFX6-7 if clrxdisasm is not found")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5591>

src/amd/compiler/aco_print_asm.cpp

index 2e6519fe57b357e4e81cfdfcf4f509bc6a39f1a9..d4b0e0edbcf3e6acb2776e35846988bf8798bd7f 100644 (file)
@@ -69,11 +69,17 @@ void print_asm_gfx6_gfx7(Program *program, std::vector<uint32_t>& binary,
    sprintf(command, "clrxdisasm --gpuType=%s -r %s", gpu_type, path);
 
    p = popen(command, "r");
-   if (!p || errno == ENOENT) {
-      out << "clrxdisasm not found\n";
-   } else {
-      while (fgets(line, sizeof(line), p))
+   if (p) {
+      if (!fgets(line, sizeof(line), p)) {
+         out << "clrxdisasm not found\n";
+         pclose(p);
+         goto fail;
+      }
+
+      do {
          out << line;
+      } while (fgets(line, sizeof(line), p));
+
       pclose(p);
    }