steakhal added a comment.

In D85528#2205094 <https://reviews.llvm.org/D85528#2205094>, @xazax.hun wrote:

> Looks reasonable to me, but I am not very familiar with the impacts of the 
> additional casts. Do we lose some modeling power when we are using the 
> regular constraint solver?
>
> For example, when we have constraints both on the original and the cased 
> symbol can the analyzer "merge" them?
>
> Something like:
>
>   ScopedPrimitive sym = conjure<ScopedPrimitive>();
>   if (sym == ScopedPrimitive::Max)
>     return;
>   int sym2 = static_cast<unsigned char>(sym);
>   if (sym2 == 0)
>     return;
>   // Do we know here that both sym and sym2 has the same range?
>   // Is there a change in the behavior compared to before the patch?

Huh, it's a really interesting question.
Here is the result:

---

Here is the test code:

  enum class ScopedPrimitive : unsigned char { Min = 2, Max = 8 };
  void foo() {
    auto sym = conjure<ScopedPrimitive>();
    if (sym == ScopedPrimitive::Max)
      return;
  
    int sym2 = static_cast<unsigned char>(sym);
    if (sym2 == 0)
      return;
  
    // Do we know here that both sym and sym2 has the same range?
    // Is there a change in the behavior compared to before the patch?
    clang_analyzer_printState();
    (void)sym;
    (void)sym2;
  }

Before the patch:

  "constraints": [
      { "symbol": "conj_$2{enum ScopedPrimitive, LC1, S1083, #1}", "range": "{ 
[1, 7], [9, 255] }" }
    ]

After the patch:

  "constraints": [
      { "symbol": "conj_$2{enum ScopedPrimitive, LC1, S1881, #1}", "range": "{ 
[0, 7], [9, 255] }" },
      { "symbol": "(unsigned char) (conj_$2{enum ScopedPrimitive, LC1, S1881, 
#1})", "range": "{ [1, 255] }" }
    ]



---

> For example, when we have constraints both on the original and the cased 
> symbol can the analyzer "merge" them?

Apparently, not xD.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85528/new/

https://reviews.llvm.org/D85528

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to