================
@@ -657,6 +657,16 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
       Warnings.insert(Warnings.begin(), "vector-conversion");
     if (!llvm::is_contained(Warnings, "matrix-conversion"))
       Warnings.insert(Warnings.begin(), "matrix-conversion");
+
+    // HLSL booleans in memory are i32; any non-zero value is true.
+    // Use icmp-ne rather than truncation to avoid InstCombine rewriting
+    // trunc i32 to i1 into an illegal wide <N x i1> bitcast (issue #140824).
+    if (!Args.hasArg(OPT_load_bool_from_mem))
+      CodeGenOpts.setLoadBoolFromMem(CodeGenOptions::BoolFromMem::NonZero);
+    else if (CodeGenOpts.getLoadBoolFromMem() !=
+             CodeGenOptions::BoolFromMem::NonZero)
+      Diags.Report(diag::warn_hlsl_bool_from_mem)
+          << Args.getLastArg(OPT_load_bool_from_mem)->getValue();
----------------
joaosaffran wrote:

I believe an `explicit -load-bool-from-mem=truncate` reaches the warning branch 
without changing `CodeGenOpts`, so truncation remains active even though the 
diagnostic says the option is ignored.

```suggestion
    if (Args.hasArg(OPT_load_bool_from_mem) &&
        CodeGenOpts.getLoadBoolFromMem() != 
CodeGenOptions::BoolFromMem::NonZero)
      Diags.Report(diag::warn_hlsl_bool_from_mem)
          << Args.getLastArg(OPT_load_bool_from_mem)->getValue();
    CodeGenOpts.setLoadBoolFromMem(CodeGenOptions::BoolFromMem::NonZero);
```

https://github.com/llvm/llvm-project/pull/221105
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to