github / github/codeql

CodeQL reports incorrect struct size for std::function

Đang mở
#11,790 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
C++ question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

I've got a test case where CodeQL reports different structure sizes than the actual compiler.

This is using a recent compile of LLVM 15.0.6, on an M1 Mac, as well as the default OS clang binary. I have a fresh install of CodeQL, version 2.11.6.
Notably, this only happens when using `clang++`, and not when I use `g++`.

Minimized source file:
```
#include

struct Wrapper {
std::function foo;
};

int main()
{
printf("size %ld\n", sizeof(Wrapper));
}
```

Compilation command:
```
codeql database create ./clang_db --overwrite --language=cpp --command="/Users/b/tools/llvm-project/build/bin/clang++ -std=c++17 ./test.cpp -o clang_test"
```

CodeQL query:
```
import cpp

from Class c
where c.getName() = "Wrapper"
select c.getName(), c.getSize()
```

CodeQL Output
```
Compiling query plan for /Users/b/projects/DataCov/codeql/temp.ql.
[1/1 comp 2.4s] Compiled /Users/b/projects/DataCov/codeql/temp.ql.
temp.ql: Evaluation completed (124ms).
| col0 | col1 |
+---------+------+
| Wrapper | 48 |
Shutting down query evaluator.
```

Running `clang_test`
```
size 32
```

Notably, the `g++` compiled version reports the same size as CodeQL.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.