Skip to content

There is no output when I use command clang -cc1 -analyze -analyzer-checker=debug.ViewExplodedGraph test.c to dump the ExplodedGraph of test.c #53873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
for-just-we opened this issue Feb 16, 2022 · 11 comments

Comments

@for-just-we
Copy link

When I use this command, shell output is Warning: viewing graph requires assertions, What does that means? And there is no any .dot file output. What should I do to view the ExplodedGraph of test.c.

The LLVM version I use is 12.0.0,I directly downloaded the released package instead of compiling from source code, the graphviz version I use is 2.40.1.

@Snape3058
Copy link
Member

llvm::errs() << "Warning: viewing graph requires assertions" << "\n";

llvm::errs() << "Warning: viewing graph requires assertions" << "\n";

These two lines are wrapped with macro NDEBUG. If this macro is defined, it will only output this warning and exit directly.
You need to re-compile your tool with assertions enabled.
Although debug checkers are available in release build, such functionality is disabled if assertions are disabled.

@for-just-we
Copy link
Author

Thank you, may I ask where could I enable this assertion?

@Snape3058
Copy link
Member

You need to re-compile your clang to enable this.
For debug build (CMAKE_BUILD_TYPE is Debug), it is enabled by default.
For release build (CMAKE_BUILD_TYPE is Release/RelWithDebInfo/MinSizeRel), you need to add -DLLVM_ENABLE_ASSERTIONS=ON during cmake.

@steakhal
Copy link
Contributor

Proposed fix: https://reviews.llvm.org/D124442

steakhal pushed a commit that referenced this issue May 2, 2022
Historically, exploded graph dumps were disabled in non-debug builds.
It was done so probably because a regular user should not dump the
internal representation of the analyzer anyway and the dump methods
might introduce unnecessary binary size overhead.

It turns out some of the users actually want to dump this.

Note that e.g. `LiveExpressionsDumper`, `LiveVariablesDumper`,
`ControlDependencyTreeDumper` etc. worked previously, and they are
unaffected by this change.
However, `CFGViewer` and `CFGDumper` still won't work for a similar
reason. AFAIK only these two won't work after this change.

Addresses #53873

---

**baseline**

| binary | size | size after strip |
| clang | 103M | 83M |
| clang-tidy | 67M | 54M |

**after this change**

| binary | size | size after strip |
| clang | 103M | 84M |
| clang-tidy | 67M | 54M |

CMake configuration:
```
cmake -S llvm -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
-DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_USE_LINKER=lld
-DLLVM_ENABLE_DUMP=OFF -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
-DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_TARGETS_TO_BUILD="X86"
```
Built by `clang-14.0.0`.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124442
@steakhal steakhal closed this as completed May 2, 2022
@xhslyx
Copy link

xhslyx commented May 13, 2022

Please tell me how to solve the following problem when I recompile:
-- clang project is enabled CMake Error at CMakeLists.txt:100 (message): LLVM_ENABLE_PROJECTS requests clang but directory not found: /home/zzh/llvm-source-code/llvm/../clang
This is the command I used:
zzh@server:~/llvm-source-code/build$ cmake -G "Unix Makefiles" ../llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
I've installed clang before and want to recompile it

@steakhal
Copy link
Contributor

steakhal commented May 13, 2022

I don't understand your problem. Could you please provide more details?
What is the observed behavior and what did you expect instead?

@xhslyx
Copy link

xhslyx commented May 14, 2022

OK, THANKS.
I previously installed clang by way of release, but ViewCFG this function does not work properly, I saw the previous issue can be solved by recompiling the method to specify -DLLCM_ENABLE_ASSERTIONS=ON.
However, I encountered the above problem when recompiling and it did not compile successfully, the above is the error message given and the compile command I used

@steakhal
Copy link
Contributor

However, I encountered the above problem when recompiling and it did not compile successfully, the above is the error message given and the compile command I used the above is the error message given and the compile command I used.

Okay, it seems like something really messed up. What version (commit hash) of llvm-project do you try to compile?
There should be a clang directory at the same level where the llvm directory is.

PS: I was really confused since you mentioned that you got some error during build time, but it seems like cmake configure failed.

@xhslyx
Copy link

xhslyx commented May 16, 2022

However, I encountered the above problem when recompiling and it did not compile successfully, the above is the error message given and the compile command I used the above is the error message given and the compile command I used.

Okay, it seems like something really messed up. What version (commit hash) of llvm-project do you try to compile? There should be a clang directory at the same level where the llvm directory is.

PS: I was really confused since you mentioned that you got some error during build time, but it seems like cmake configure failed.

Thank you for your answer.
It's my expression wrong, my error happened in the cmake phase, not in the build phase, sorry。
The version i try to compile is clang version 10.0.0 llvm 10.0.0
I have no clang directory at the asme level where the llvm directory is, the directory is source code/llvm/tools/clang

@steakhal
Copy link
Contributor

I would recommend using the monorepo version where clang and llvm are in a merged repository.
I cannot support the old repository structure. Let me know if using the monorepo worked.

@xhslyx
Copy link

xhslyx commented May 16, 2022

ok, i'll rebuild in monorepo version. Thanks:)

haoNoQ pushed a commit to swiftlang/llvm-project that referenced this issue Jul 19, 2022
Historically, exploded graph dumps were disabled in non-debug builds.
It was done so probably because a regular user should not dump the
internal representation of the analyzer anyway and the dump methods
might introduce unnecessary binary size overhead.

It turns out some of the users actually want to dump this.

Note that e.g. `LiveExpressionsDumper`, `LiveVariablesDumper`,
`ControlDependencyTreeDumper` etc. worked previously, and they are
unaffected by this change.
However, `CFGViewer` and `CFGDumper` still won't work for a similar
reason. AFAIK only these two won't work after this change.

Addresses llvm#53873

---

**baseline**

| binary | size | size after strip |
| clang | 103M | 83M |
| clang-tidy | 67M | 54M |

**after this change**

| binary | size | size after strip |
| clang | 103M | 84M |
| clang-tidy | 67M | 54M |

CMake configuration:
```
cmake -S llvm -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
-DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_USE_LINKER=lld
-DLLVM_ENABLE_DUMP=OFF -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
-DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_TARGETS_TO_BUILD="X86"
```
Built by `clang-14.0.0`.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124442

(cherry picked from commit 5ce7050)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants