Skip to content

Commit e25f22d

Browse files
committed
Merge main into redsun82/swift-extraction
2 parents 1fc2bc4 + 46e6203 commit e25f22d

File tree

57 files changed

+924
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+924
-69
lines changed

.devcontainer/swift/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/cpp/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/22.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
4+
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-ubuntu-22.04
5+
6+
USER root
7+
ADD root.sh /tmp/root.sh
8+
ADD update-codeql.sh /usr/local/bin/update-codeql
9+
RUN bash /tmp/root.sh && rm /tmp/root.sh

.devcontainer/swift/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extensions": [
3+
"github.vscode-codeql",
4+
"hbenl.vscode-test-explorer",
5+
"ms-vscode.test-adapter-converter",
6+
"slevesque.vscode-zipexplorer",
7+
"ms-vscode.cpptools"
8+
],
9+
"settings": {
10+
"files.watcherExclude": {
11+
"**/target/**": true
12+
},
13+
"codeQL.runningQueries.memory": 2048
14+
},
15+
"build": {
16+
"dockerfile": "Dockerfile",
17+
},
18+
"runArgs": [
19+
"--cap-add=SYS_PTRACE",
20+
"--security-opt",
21+
"seccomp=unconfined"
22+
],
23+
"remoteUser": "vscode",
24+
"onCreateCommand": ".devcontainer/swift/user.sh"
25+
}

.devcontainer/swift/root.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set -xe
2+
3+
BAZELISK_VERSION=v1.12.0
4+
BAZELISK_DOWNLOAD_SHA=6b0bcb2ea15bca16fffabe6fda75803440375354c085480fe361d2cbf32501db
5+
6+
apt-get update
7+
export DEBIAN_FRONTEND=noninteractive
8+
apt-get -y install --no-install-recommends \
9+
zlib1g-dev \
10+
uuid-dev \
11+
python3-distutils \
12+
python3-pip \
13+
bash-completion
14+
15+
# Install Bazel
16+
curl -fSsL -o /usr/local/bin/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-linux-amd64
17+
echo "${BAZELISK_DOWNLOAD_SHA} */usr/local/bin/bazelisk" | sha256sum --check -
18+
chmod 0755 /usr/local/bin/bazelisk
19+
ln -s bazelisk /usr/local/bin/bazel
20+
21+
# install latest codeql
22+
update-codeql

.devcontainer/swift/update-codeql.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash -e
2+
3+
URL=https://github.com/github/codeql-cli-binaries/releases
4+
LATEST_VERSION=$(curl -L -s -H 'Accept: application/json' $URL/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
5+
CURRENT_VERSION=v$(codeql version 2>/dev/null | sed -ne 's/.*release \([0-9.]*\)\./\1/p')
6+
if [[ $CURRENT_VERSION != $LATEST_VERSION ]]; then
7+
if [[ $UID != 0 ]]; then
8+
echo "update required, please run this script with sudo:"
9+
echo " sudo $0"
10+
exit 1
11+
fi
12+
ZIP=$(mktemp codeql.XXXX.zip)
13+
curl -fSqL -o $ZIP $URL/download/$LATEST_VERSION/codeql-linux64.zip
14+
unzip -q $ZIP -d /opt
15+
rm $ZIP
16+
ln -sf /opt/codeql/codeql /usr/local/bin/codeql
17+
echo installed version $LATEST_VERSION
18+
else
19+
echo current version $CURRENT_VERSION is up-to-date
20+
fi

.devcontainer/swift/user.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set -xe
2+
3+
# add the workspace to the codeql search path
4+
mkdir -p /home/vscode/.config/codeql
5+
echo "--search-path /workspaces/codeql" > /home/vscode/.config/codeql/config
6+
7+
# create a swift extractor pack with the current state
8+
cd /workspaces/codeql
9+
bazel run swift/create-extractor-pack
10+
11+
#install and set up pre-commit
12+
python3 -m pip install pre-commit --no-warn-script-location
13+
$HOME/.local/bin/pre-commit install
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* `UserType.getADeclarationEntry()` now yields all forward declarations when the user type is a `class`, `struct`, or `union`.

cpp/ql/lib/semmle/code/cpp/UserType.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
4848
}
4949

5050
override TypeDeclarationEntry getADeclarationEntry() {
51-
if type_decls(_, underlyingElement(this), _)
52-
then type_decls(unresolveElement(result), underlyingElement(this), _)
51+
if type_decls(_, unresolveElement(this), _)
52+
then type_decls(underlyingElement(result), unresolveElement(this), _)
5353
else exists(Class t | this.(Class).isConstructedFrom(t) and result = t.getADeclarationEntry())
5454
}
5555

cpp/ql/test/library-tests/declarationEntry/declarationEntry/declarationEntry.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ class myTemplateClass
3333

3434
myTemplateClass<int> mtc_int;
3535
myTemplateClass<short> mtc_short;
36+
37+
// Class (UserType)
38+
39+
class myClass
40+
{
41+
public:
42+
int myMemberVariable;
43+
};

cpp/ql/test/library-tests/declarationEntry/declarationEntry/declarationEntry.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,11 @@
2727
| declarationEntry.cpp:31:4:31:19 | myMemberVariable | declarationEntry.cpp:31:4:31:19 | definition of myMemberVariable | 1 | 1 |
2828
| declarationEntry.cpp:34:22:34:28 | mtc_int | declarationEntry.cpp:34:22:34:28 | definition of mtc_int | 1 | 1 |
2929
| declarationEntry.cpp:35:24:35:32 | mtc_short | declarationEntry.cpp:35:24:35:32 | definition of mtc_short | 1 | 1 |
30+
| declarationEntry.cpp:39:7:39:7 | operator= | declarationEntry.cpp:39:7:39:7 | declaration of operator= | 1 | 1 |
31+
| declarationEntry.cpp:39:7:39:7 | operator= | declarationEntry.cpp:39:7:39:7 | declaration of operator= | 1 | 1 |
32+
| declarationEntry.cpp:39:7:39:13 | myClass | declarationEntry.cpp:39:7:39:13 | definition of myClass | 1 | 1 |
33+
| declarationEntry.cpp:39:7:39:13 | myClass | forwardDeclaration.cpp:1:7:1:13 | declaration of myClass | 1 | 1 |
34+
| declarationEntry.cpp:42:6:42:21 | myMemberVariable | declarationEntry.cpp:42:6:42:21 | definition of myMemberVariable | 1 | 1 |
35+
| forwardDeclaration.cpp:3:10:3:19 | myClassPtr | forwardDeclaration.cpp:3:10:3:19 | definition of myClassPtr | 1 | 1 |
3036
| macro.c:2:1:2:3 | foo | macro.c:2:1:2:3 | declaration of foo | 1 | 1 |
3137
| macro.c:4:5:4:8 | main | macro.c:4:5:4:8 | definition of main | 1 | 1 |

cpp/ql/test/library-tests/declarationEntry/declarationEntry/fde.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
| declarationEntry.cpp:28:7:28:7 | declaration of operator= | | 0 | |
1111
| declarationEntry.cpp:28:7:28:7 | declaration of operator= | | 0 | |
1212
| declarationEntry.cpp:28:7:28:7 | declaration of operator= | | 0 | |
13+
| declarationEntry.cpp:39:7:39:7 | declaration of operator= | | 0 | |
14+
| declarationEntry.cpp:39:7:39:7 | declaration of operator= | | 0 | |
1315
| macro.c:2:1:2:3 | declaration of foo | | 2 | c_linkage, static |
1416
| macro.c:4:5:4:8 | definition of main | | 1 | c_linkage |

0 commit comments

Comments
 (0)