[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-03-26 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey created https://github.com/llvm/llvm-project/pull/86727

This PR fixes the following issue when working with `clang-repl`:

```
fatal error: error in backend: Inline asm not supported by this streamer 
because we don't have an asm parser for this target
```

When working with the following input (named "unit.cpp"):

```cpp
__asm(".globl _ZSt21ios_base_library_initv");
int x;
```

and then in `clang-repl`:

```
#include "unit.cpp"
x = 10;
```




Signed-off-by: Andrew V. Teylu 

>From 784dd45324566775439b3c06674ab7d70b292d0b Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Tue, 26 Mar 2024 20:10:24 +
Subject: [PATCH] [clang-repl] Add call to 'InitializeAllAsmParsers'

Signed-off-by: Andrew V. Teylu 
---
 clang/tools/clang-repl/ClangRepl.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 5bad8145324d06..aecf61b97fc719 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -152,6 +152,7 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllTargets();
   llvm::InitializeAllTargetMCs();
   llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
 
   if (OptHostSupportsJit) {
 auto J = llvm::orc::LLJITBuilder().create();

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


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-03-26 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

This my first PR against LLVM; does something like this need tests? I'm 100% 
happy to add tests for this, but are there some examples of "good" `clang-repl` 
tests I can learn from/extend from?

https://github.com/llvm/llvm-project/pull/86727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-03-26 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

> This my first PR against LLVM; does something like this need tests? I'm 100% 
> happy to add tests for this, but are there some examples of "good" 
> `clang-repl` tests I can learn from/extend from?

Maybe this is reasonable:

```cpp
// REQUIRES: host-supports-jit, x86_64-linux
// UNSUPPORTED: system-aix
//
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: cat %t/inline-asm.txt | clang-repl

//--- inline-asm.cpp
__asm(".globl _ZSt21ios_base_library_initv");
int x;

//--- inline-asm.txt
#include "inline-asm.cpp"
x = 10;
%quit
```

https://github.com/llvm/llvm-project/pull/86727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-03-26 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/86727

>From 784dd45324566775439b3c06674ab7d70b292d0b Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Tue, 26 Mar 2024 20:10:24 +
Subject: [PATCH 1/2] [clang-repl] Add call to 'InitializeAllAsmParsers'

Signed-off-by: Andrew V. Teylu 
---
 clang/tools/clang-repl/ClangRepl.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 5bad8145324d06..aecf61b97fc719 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -152,6 +152,7 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllTargets();
   llvm::InitializeAllTargetMCs();
   llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
 
   if (OptHostSupportsJit) {
 auto J = llvm::orc::LLJITBuilder().create();

>From 04e6bbdbcda1173fcfb872bd4bcbb110e9ca5ffc Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Tue, 26 Mar 2024 20:49:53 +
Subject: [PATCH 2/2] [clang-repl] add test for inline asm

Signed-off-by: Andrew V. Teylu 
---
 clang/test/Interpreter/inline-asm.cpp | 17 +
 1 file changed, 17 insertions(+)
 create mode 100644 clang/test/Interpreter/inline-asm.cpp

diff --git a/clang/test/Interpreter/inline-asm.cpp 
b/clang/test/Interpreter/inline-asm.cpp
new file mode 100644
index 00..f94f14df72f80e
--- /dev/null
+++ b/clang/test/Interpreter/inline-asm.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: host-supports-jit, x86_64-linux
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: cat %t/inline-asm.txt | clang-repl -Xcc="-I%t"
+
+//--- inline-asm.cpp
+__asm(".globl _ZSt21ios_base_library_initv");
+int x;
+
+//--- inline-asm.txt
+#include "inline-asm.cpp"
+x = 10;
+%quit

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


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-03-26 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

```avj@host /tmp/clang_build$ ./bin/llvm-lit -v 
/tmp/llvm-project/clang/test/Interpreter/inline-asm.cpp
llvm-lit: /tmp/llvm-project/llvm/utils/lit/lit/llvm/config.py:502: note: using 
clang: /tmp/clang_build/bin/clang
-- Testing: 1 tests, 1 workers --
PASS: Clang :: Interpreter/inline-asm.cpp (1 of 1)

Testing Time: 0.10s

Total Discovered Tests: 1
  Passed: 1 (100.00%)
```

https://github.com/llvm/llvm-project/pull/86727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-04-02 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/86727

>From 480d77eb88df2abc589c4be90ceab200cb3fac98 Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Tue, 26 Mar 2024 20:10:24 +
Subject: [PATCH 1/2] [clang-repl] Add call to 'InitializeAllAsmParsers'

Signed-off-by: Andrew V. Teylu 
---
 clang/tools/clang-repl/ClangRepl.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 5bad8145324d06..aecf61b97fc719 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -152,6 +152,7 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllTargets();
   llvm::InitializeAllTargetMCs();
   llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
 
   if (OptHostSupportsJit) {
 auto J = llvm::orc::LLJITBuilder().create();

>From d1e104977e22c4d641459714c4e45acdb87576b1 Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Tue, 26 Mar 2024 20:49:53 +
Subject: [PATCH 2/2] [clang-repl] add test for inline asm

Signed-off-by: Andrew V. Teylu 
---
 clang/test/Interpreter/inline-asm.cpp | 17 +
 1 file changed, 17 insertions(+)
 create mode 100644 clang/test/Interpreter/inline-asm.cpp

diff --git a/clang/test/Interpreter/inline-asm.cpp 
b/clang/test/Interpreter/inline-asm.cpp
new file mode 100644
index 00..f94f14df72f80e
--- /dev/null
+++ b/clang/test/Interpreter/inline-asm.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: host-supports-jit, x86_64-linux
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: cat %t/inline-asm.txt | clang-repl -Xcc="-I%t"
+
+//--- inline-asm.cpp
+__asm(".globl _ZSt21ios_base_library_initv");
+int x;
+
+//--- inline-asm.txt
+#include "inline-asm.cpp"
+x = 10;
+%quit

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


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-04-02 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

@weliveindetail @vgvassilev @junaire: sorry for pinging you directly, but could 
you take a look at this PR? I see you're all active on other `clang-repl` PRs, 
so thought you might be the best place to start to take a look at this one 🤞 

https://github.com/llvm/llvm-project/pull/86727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Add call to 'InitializeAllAsmParsers' (PR #86727)

2024-04-02 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

> > @weliveindetail @vgvassilev @junaire: sorry for pinging you directly, but 
> > could you take a look at this PR? I see you're all active on other 
> > `clang-repl` PRs, so thought you might be the best place to start to take a 
> > look at this one 🤞
> 
> Hi, thanks for the PR. I think the change looks reasonable but I'm no longer 
> working on this so I've picked some reviewers for you. They should be able to 
> look at this soon.

Thank you very much :)

https://github.com/llvm/llvm-project/pull/86727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-04 Thread Andrew V. Teylu via cfe-commits


@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts

aytey wrote:

Actually, that's a good point.

I added that bit because the only way I can *guarantee* it will crash (with 
main) is if we have asserts on.

I'll remove this, but if someone wants to check the test I added and they go 
"hey, this works on main!", then hopefully they'll try an assertion-enabled 
build 🙏 

https://github.com/llvm/llvm-project/pull/87521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-04 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/87521

>From 1f70839ea1607f151c9f7eb390fcb974b32a54ca Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/non_loc_compound.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887a..1f3e5711bcc71c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2836,6 +2836,10 @@ bool RangeConstraintManager::canReasonAbout(SVal X) 
const {
 return false;
   }
 
+  // Non-integer types are not supported.
+  if (X.getAs())
+return false;
+
   return true;
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 8ca2cdb9d3ab7a..b84a68ab93ef90 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -57,10 +57,14 @@ ProgramStateRef 
SimpleConstraintManager::assumeAux(ProgramStateRef State,
   // We cannot reason about SymSymExprs, and can only reason about some
   // SymIntExprs.
   if (!canReasonAbout(Cond)) {
-// Just add the constraint to the expression without trying to simplify.
 SymbolRef Sym = Cond.getAsSymbol();
-assert(Sym);
-return assumeSymUnsupported(State, Sym, Assumption);
+if (Sym) {
+  // this will simplify the symbol, so only call this if we have a
+  // symbol.
+  return assumeSymUnsupported(State, Sym, Assumption);
+} else {
+  return State;
+}
   }
 
   switch (Cond.getKind()) {
diff --git a/clang/test/Analysis/non_loc_compound.cpp 
b/clang/test/Analysis/non_loc_compound.cpp
new file mode 100644
index 00..b76ecb8d56635c
--- /dev/null
+++ b/clang/test/Analysis/non_loc_compound.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=alpha.cplusplus.InvalidatedIterator \
+// RUN:   -analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:   2>&1
+
+struct node {};
+struct prop : node {};
+struct bitvec : node {
+  prop operator==(bitvec) { return prop(); }
+  bitvec extend(); // { return *this; }
+};
+void convert() {
+  bitvec input;
+  bitvec output(input.extend());
+  output == input;
+}

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


[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-04 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

> I suspect that you're loading checkers as clang plugins and one of them is 
> causing it.

So here's how I'm invoking `clang` for those crashes:

* `./bin/clang -cc1 -analyze -analyzer-checker=nullability.NullPassedToNonnull 
-analyzer-config aggressive-binary-operation-simplification=true `

For those crashes `` can be anything (even empty!) and you get the same 
backtrace.

> There's something else going on.

Yeah, I'd agree with that! 😄 

https://github.com/llvm/llvm-project/pull/87521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-04 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/87521

>From 1f70839ea1607f151c9f7eb390fcb974b32a54ca Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 1/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/non_loc_compound.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887a..1f3e5711bcc71c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2836,6 +2836,10 @@ bool RangeConstraintManager::canReasonAbout(SVal X) 
const {
 return false;
   }
 
+  // Non-integer types are not supported.
+  if (X.getAs())
+return false;
+
   return true;
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 8ca2cdb9d3ab7a..b84a68ab93ef90 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -57,10 +57,14 @@ ProgramStateRef 
SimpleConstraintManager::assumeAux(ProgramStateRef State,
   // We cannot reason about SymSymExprs, and can only reason about some
   // SymIntExprs.
   if (!canReasonAbout(Cond)) {
-// Just add the constraint to the expression without trying to simplify.
 SymbolRef Sym = Cond.getAsSymbol();
-assert(Sym);
-return assumeSymUnsupported(State, Sym, Assumption);
+if (Sym) {
+  // this will simplify the symbol, so only call this if we have a
+  // symbol.
+  return assumeSymUnsupported(State, Sym, Assumption);
+} else {
+  return State;
+}
   }
 
   switch (Cond.getKind()) {
diff --git a/clang/test/Analysis/non_loc_compound.cpp 
b/clang/test/Analysis/non_loc_compound.cpp
new file mode 100644
index 00..b76ecb8d56635c
--- /dev/null
+++ b/clang/test/Analysis/non_loc_compound.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=alpha.cplusplus.InvalidatedIterator \
+// RUN:   -analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:   2>&1
+
+struct node {};
+struct prop : node {};
+struct bitvec : node {
+  prop operator==(bitvec) { return prop(); }
+  bitvec extend(); // { return *this; }
+};
+void convert() {
+  bitvec input;
+  bitvec output(input.extend());
+  output == input;
+}

>From 9f552209d9ce9bbddca247a46f79b331388908bf Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 2/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 fi

[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-08 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/87521

>From 1f70839ea1607f151c9f7eb390fcb974b32a54ca Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 1/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/non_loc_compound.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887a..1f3e5711bcc71c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2836,6 +2836,10 @@ bool RangeConstraintManager::canReasonAbout(SVal X) 
const {
 return false;
   }
 
+  // Non-integer types are not supported.
+  if (X.getAs())
+return false;
+
   return true;
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 8ca2cdb9d3ab7a..b84a68ab93ef90 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -57,10 +57,14 @@ ProgramStateRef 
SimpleConstraintManager::assumeAux(ProgramStateRef State,
   // We cannot reason about SymSymExprs, and can only reason about some
   // SymIntExprs.
   if (!canReasonAbout(Cond)) {
-// Just add the constraint to the expression without trying to simplify.
 SymbolRef Sym = Cond.getAsSymbol();
-assert(Sym);
-return assumeSymUnsupported(State, Sym, Assumption);
+if (Sym) {
+  // this will simplify the symbol, so only call this if we have a
+  // symbol.
+  return assumeSymUnsupported(State, Sym, Assumption);
+} else {
+  return State;
+}
   }
 
   switch (Cond.getKind()) {
diff --git a/clang/test/Analysis/non_loc_compound.cpp 
b/clang/test/Analysis/non_loc_compound.cpp
new file mode 100644
index 00..b76ecb8d56635c
--- /dev/null
+++ b/clang/test/Analysis/non_loc_compound.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=alpha.cplusplus.InvalidatedIterator \
+// RUN:   -analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:   2>&1
+
+struct node {};
+struct prop : node {};
+struct bitvec : node {
+  prop operator==(bitvec) { return prop(); }
+  bitvec extend(); // { return *this; }
+};
+void convert() {
+  bitvec input;
+  bitvec output(input.extend());
+  output == input;
+}

>From 9f552209d9ce9bbddca247a46f79b331388908bf Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 2/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 fi

[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-10 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/87521

>From 1f70839ea1607f151c9f7eb390fcb974b32a54ca Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 1/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/non_loc_compound.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887a..1f3e5711bcc71c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2836,6 +2836,10 @@ bool RangeConstraintManager::canReasonAbout(SVal X) 
const {
 return false;
   }
 
+  // Non-integer types are not supported.
+  if (X.getAs())
+return false;
+
   return true;
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 8ca2cdb9d3ab7a..b84a68ab93ef90 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -57,10 +57,14 @@ ProgramStateRef 
SimpleConstraintManager::assumeAux(ProgramStateRef State,
   // We cannot reason about SymSymExprs, and can only reason about some
   // SymIntExprs.
   if (!canReasonAbout(Cond)) {
-// Just add the constraint to the expression without trying to simplify.
 SymbolRef Sym = Cond.getAsSymbol();
-assert(Sym);
-return assumeSymUnsupported(State, Sym, Assumption);
+if (Sym) {
+  // this will simplify the symbol, so only call this if we have a
+  // symbol.
+  return assumeSymUnsupported(State, Sym, Assumption);
+} else {
+  return State;
+}
   }
 
   switch (Cond.getKind()) {
diff --git a/clang/test/Analysis/non_loc_compound.cpp 
b/clang/test/Analysis/non_loc_compound.cpp
new file mode 100644
index 00..b76ecb8d56635c
--- /dev/null
+++ b/clang/test/Analysis/non_loc_compound.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=alpha.cplusplus.InvalidatedIterator \
+// RUN:   -analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:   2>&1
+
+struct node {};
+struct prop : node {};
+struct bitvec : node {
+  prop operator==(bitvec) { return prop(); }
+  bitvec extend(); // { return *this; }
+};
+void convert() {
+  bitvec input;
+  bitvec output(input.extend());
+  output == input;
+}

>From 9f552209d9ce9bbddca247a46f79b331388908bf Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 2/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 fi

[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-10 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

@steakhal @haoNoQ how's this looking to you? anything further for me to do?

https://github.com/llvm/llvm-project/pull/87521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits