Skip to content
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

[BUG] CodeQL Fails to Process --include=<arg> in clang Commands #18019

Open
cradiator opened this issue Nov 19, 2024 · 4 comments
Open

[BUG] CodeQL Fails to Process --include=<arg> in clang Commands #18019

cradiator opened this issue Nov 19, 2024 · 4 comments
Labels
bug Something isn't working C++

Comments

@cradiator
Copy link

Summary

CodeQL does not handle the --include=<arg> format correctly when used in Clang commands.

In Clang, the --include option instructs the compiler to include macros from a file before parsing. It can be specified in three formats: -include<file>, --include<file>, and --include=<arg>. However, CodeQL fails to correctly interpret the --include=<arg> format.

https://clang.llvm.org/docs/ClangCommandLineReference.html

Steps to Reproduce

codeql database create --language=cpp --command="clang --include=header.h -c main.c -o main.o" --overwrite ./db

Expected Behavior

The database should contain information from main.c.

Actual Behavior

The resulting database does not include information from main.c.

Error Log

The extractor's error log shows the following warning:

linux64/extractor ... --preinclude '=header.h'

...
[E 00:10:05 3930451] Warning[extractor-c++]: In construct_text_message: Command-line error: cannot open source file "=header.h"

This indicates that the extractor incorrectly interprets =header.h as the file name, rather than recognizing header.h as the intended include file.

@cradiator cradiator added the question Further information is requested label Nov 19, 2024
@aibaars
Copy link
Contributor

aibaars commented Nov 19, 2024

You are right. Even though clang's documentation does not mention the = sign in its man pages, it is allowed

       -include <filename>
              Adds an implicit #include into the predefines buffer which is read before the source file is preprocessed.

I'll let the team know. As a workaround, could you try leaving out the = sign in the command?

Thanks for reporting!

@jketema
Copy link
Contributor

jketema commented Nov 19, 2024

Hi @cradiator,

Could you share the build-tracer.log file created during database creation? It's not clear to me whether clang is ran with an integrated cc1 in your case, and the log file should clear that up (any fix will depend on that).

@intrigus-lgtm
Copy link
Contributor

You are right. Even though clang's documentation does not mention the = sign in its man pages, it is allowed

       -include <filename>
              Adds an implicit #include into the predefines buffer which is read before the source file is preprocessed.

I guess the man page is just outdated as the online documentation lists it:
https://clang.llvm.org/docs/ClangCommandLineReference.html#include-path-management

@cradiator
Copy link
Author

@aibaars Yes, I tried "--includeheader.h" and it works, the output database contains main.c's information.

@jketema Here is is the build-tracer.log for your reference.
build-tracer.log

@jketema jketema added bug Something isn't working C++ and removed question Further information is requested labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C++
Projects
None yet
Development

No branches or pull requests

4 participants