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

ci: Add Github Action for codeql #524

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "CodeQL"

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
# schedule:
# - cron: '0 7 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['cpp', 'python']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
#- name: Autobuild
# uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

- run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DFIZZY_TESTING=ON -DFIZZY_WASI=ON
cmake --build .

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
5 changes: 2 additions & 3 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ T fnearest(T value) noexcept
}

template <typename T>
__attribute__((no_sanitize("float-divide-by-zero"))) inline constexpr T fdiv(T a, T b) noexcept
[[gnu::no_sanitize("float-divide-by-zero")]] inline constexpr T fdiv(T a, T b) noexcept
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chfast is it useful merging these changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it doesn't work as the sanitizer task reports division-by-zero.

{
static_assert(std::is_floating_point_v<T>);
static_assert(std::numeric_limits<T>::is_iec559);
Expand Down Expand Up @@ -495,8 +495,7 @@ inline T fmax(T a, T b) noexcept
}


__attribute__((no_sanitize("float-cast-overflow"))) inline constexpr float demote(
double value) noexcept
[[gnu::no_sanitize("float-cast-overflow")]] inline constexpr float demote(double value) noexcept
{
// The float-cast-overflow UBSan check disabled for this conversion. In older clang versions
// (up to 8.0) it reports a failure when non-infinity f64 value is converted to f32 infinity.
Expand Down
26 changes: 24 additions & 2 deletions lib/fizzy/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,34 @@ enum class ExternalKind : uint8_t
// https://webassembly.github.io/spec/core/binary/modules.html#import-section
struct Import
{
Import() = default;
Import(const Import& other) : module(other.module), name(other.name), kind(other.kind)
{
switch (other.kind)
{
case ExternalKind::Function:
desc.function_type_index = other.desc.function_type_index;
break;
case ExternalKind::Table:
desc.table = other.desc.table;
break;
case ExternalKind::Memory:
desc.memory = other.desc.memory;
break;
case ExternalKind::Global:
desc.global = other.desc.global;
break;
}
}
// TODO needs move constructor

std::string module;
std::string name;
ExternalKind kind = ExternalKind::Function;
union
union Desc
{
TypeIdx function_type_index = 0;
Desc() : function_type_index(0) {}
TypeIdx function_type_index;
Memory memory;
GlobalType global;
Table table;
Expand Down