Skip to content

Commit f9aa3ab

Browse files
committed
ci: enable ubsan for clang and GCC
1 parent 5372fdf commit f9aa3ab

File tree

4 files changed

+51
-68
lines changed

4 files changed

+51
-68
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ jobs:
4141
standards: '20'
4242
latest-factors: |
4343
msvc Optimized-Debug
44-
gcc Coverage
44+
gcc UBSan Coverage
45+
clang UBSan
4546
factors: ''
4647
runs-on: |
4748
apple-clang: macos-15
@@ -65,21 +66,21 @@ jobs:
6566
msvc: ''
6667
extra-values: |
6768
llvm-hash: dd7a3d4d798e30dfe53b5bbbbcd9a23c24ea1af9
68-
llvm-id: {{ substr llvm-hash 0 7 }}
69-
llvm-build-preset-prefix: {{#if optimized-debug}}debwithopt{{else}}{{lowercase build-type}}{{/if}}
70-
llvm-build-preset-suffix: {{#if (ieq os 'windows') }}win{{else}}unix{{/if}}
71-
llvm-build-preset: {{ llvm-build-preset-prefix }}-{{ llvm-build-preset-suffix }}
72-
llvm-compiler-key: {{ compiler }}-{{ version }}
73-
llvm-cache-key: llvm-libcxx-{{ lowercase os }}-{{ llvm-compiler-key }}-{{ llvm-build-preset-prefix }}-{{ llvm-hash }}
69+
llvm-build-preset-prefix: {{#if optimized-debug}}debwithopt{{else}}{{{lowercase build-type}}}{{/if}}
70+
llvm-build-preset-os: {{#if (ieq os 'windows') }}win{{else}}unix{{/if}}
71+
llvm-sanitizer: {{#if ubsan}}-UBSan{{else if asan}}-ASan{{else if msan}}-MSan{{/if}}
72+
llvm-build-preset: {{{ llvm-build-preset-prefix }}}-{{{ llvm-build-preset-os }}}
73+
llvm-compiler-version: {{#if (ieq compiler 'apple-clang')}}{{else if (ieq compiler 'msvc')}}-{{{ substr version 1 999 }}}{{else}}-{{{ version }}}{{/if}}
74+
llvm-archive-basename: llvm-{{{ lowercase os }}}-{{{ compiler }}}{{{ llvm-compiler-version }}}-{{{ llvm-build-preset-prefix }}}{{{ sanitizer }}}-{{{ substr llvm-hash 0 7 }}}
7475
llvm-root: ../third-party/llvm-project/install
75-
llvm-archive-basename: llvm-{{ os }}-{{ llvm-build-preset-prefix }}-{{ llvm-id }}
7676
llvm-archive-extension: {{#if (ieq os 'windows') }}7z{{else}}tar.bz2{{/if}}
77-
llvm-archive-filename: {{ llvm-archive-basename }}.{{ llvm-archive-extension }}
78-
mrdocs-ccflags: {{ ccflags }} {{#if (eq compiler 'gcc') }}-static{{/if}} {{#if asan }}-static-libasan{{/if}} {{#if tsan }}-static-libtsan{{/if}}
79-
mrdocs-cxxflags: {{ cxxflags }} {{#if (eq compiler 'gcc') }}-static{{/if}} {{#if asan }}-static-libasan{{/if}} {{#if tsan }}-static-libtsan{{/if}}
77+
llvm-archive-filename: {{{ llvm-archive-basename }}}.{{{ llvm-archive-extension }}}
78+
mrdocs-ccflags: {{{ ccflags }}} {{#if (and (eq compiler 'gcc') (not asan)) }}-static{{/if}}
79+
mrdocs-cxxflags: {{{ cxxflags }}} {{#if (and (eq compiler 'gcc') (not asan)) }}-static{{/if}}
8080
mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}}
81-
mrdocs-release-package-artifact: release-packages-{{ lowercase os }}
81+
mrdocs-release-package-artifact: release-packages-{{{ lowercase os }}}
8282
output-file: matrix.json
83+
trace-commands: true
8384

8485
# Set up the version as expected by the LLVM matrix script and @actions/core
8586
- name: Setup Node.js
@@ -211,7 +212,7 @@ jobs:
211212
uses: actions/cache@v4
212213
with:
213214
path: ${{ steps.resolve-llvm-root.outputs.llvm-root }}
214-
key: ${{ matrix.llvm-cache-key }}
215+
key: ${{ matrix.llvm-archive-basename }}
215216

216217
- name: Download LLVM Binaries
217218
id: llvm-download
@@ -260,6 +261,10 @@ jobs:
260261
build-type: ${{ matrix.build-type }}
261262
extra-args: |
262263
${{ runner.os == 'Windows' && '-DLLVM_ENABLE_RUNTIMES=libcxx' || '-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind' }}
264+
# The UBSan vptr sanitizer needs RTTI.
265+
${{ matrix.ubsan && '-DLLVM_ENABLE_RTTI=ON' }}
266+
# The LLVM_USE_SANITIZER option doesn't support GCC.
267+
${{ !matrix.compiler == 'gcc' && matrix.ubsan && '-DLLVM_USE_SANITIZER=Undefined' }}
263268
cc: ${{ steps.setup-cpp.outputs.cc }}
264269
cxx: ${{ steps.setup-cpp.outputs.cxx }}
265270
generator: Ninja
@@ -868,7 +873,7 @@ jobs:
868873
uses: actions/cache@v4
869874
with:
870875
path: ${{ steps.resolve-llvm-root.outputs.llvm-root }}
871-
key: ${{ matrix.llvm-cache-key }}
876+
key: ${{ matrix.llvm-archive-basename }}
872877

873878
- name: Compress LLVM
874879
id: llvm-upload

src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ inheritBaseMembers(
107107
Info& otherInfo = *otherInfoPtr;
108108

109109
// Check if we're not attempt to copy a special member function
110-
if (auto const* funcPtr = static_cast<FunctionInfo const*>(otherInfoPtr))
111-
{
112-
MRDOCS_CHECK_OR_CONTINUE(!is_one_of(
113-
funcPtr->Class,
114-
{ FunctionClass::Constructor, FunctionClass::Destructor }));
110+
if (auto const *funcPtr =
111+
dynamic_cast<FunctionInfo const *>(otherInfoPtr)) {
112+
MRDOCS_CHECK_OR_CONTINUE(
113+
!is_one_of(funcPtr->Class, {FunctionClass::Constructor,
114+
FunctionClass::Destructor}));
115115
}
116116

117117
// Check if derived class has a member that shadows the base member

src/lib/Support/Yaml.cpp

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,33 @@
1515
namespace clang {
1616
namespace mrdocs {
1717

18-
void
19-
YamlReporter::
20-
diag(
21-
llvm::SMDiagnostic const& D)
22-
{
23-
report::Level level = report::Level::debug;
24-
switch(D.getKind())
25-
{
26-
case llvm::SourceMgr::DiagKind::DK_Remark:
27-
level = report::Level::debug;
28-
break;
29-
case llvm::SourceMgr::DiagKind::DK_Note:
30-
level = report::Level::info;
31-
break;
32-
case llvm::SourceMgr::DiagKind::DK_Warning:
33-
{
34-
if(D.getMessage().starts_with("unknown key "))
35-
{
36-
// don't show these
37-
return;
38-
}
39-
level = report::Level::warn;
40-
break;
18+
void YamlReporter::diag(llvm::SMDiagnostic const &D, void *) {
19+
report::Level level = report::Level::debug;
20+
switch (D.getKind()) {
21+
case llvm::SourceMgr::DiagKind::DK_Remark:
22+
level = report::Level::debug;
23+
break;
24+
case llvm::SourceMgr::DiagKind::DK_Note:
25+
level = report::Level::info;
26+
break;
27+
case llvm::SourceMgr::DiagKind::DK_Warning: {
28+
if (D.getMessage().starts_with("unknown key ")) {
29+
// don't show these
30+
return;
4131
}
42-
case llvm::SourceMgr::DiagKind::DK_Error:
43-
level = report::Level::error;
44-
break;
45-
default:
46-
MRDOCS_UNREACHABLE();
47-
}
48-
49-
report::call_impl(
50-
level,
51-
[&](llvm::raw_ostream& os)
52-
{
53-
D.print("mrdocs", os, true, true);
54-
}, nullptr);
55-
}
32+
level = report::Level::warn;
33+
break;
34+
}
35+
case llvm::SourceMgr::DiagKind::DK_Error:
36+
level = report::Level::error;
37+
break;
38+
default:
39+
MRDOCS_UNREACHABLE();
40+
}
5641

57-
void
58-
YamlReporter::
59-
diagFnImpl(
60-
llvm::SMDiagnostic const& D, void* ctx)
61-
{
62-
reinterpret_cast<YamlReporter*>(ctx)->diag(D);
42+
report::call_impl(
43+
level, [&](llvm::raw_ostream &os) { D.print("mrdocs", os, true, true); },
44+
nullptr);
6345
}
6446

6547
} // mrdocs

src/lib/Support/Yaml.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@ namespace mrdocs {
2121
class MRDOCS_DECL
2222
YamlReporter
2323
{
24-
void diag(llvm::SMDiagnostic const&);
25-
static void diagFnImpl(llvm::SMDiagnostic const&, void*);
24+
static void diag(llvm::SMDiagnostic const &, void *);
2625

2726
public:
2827
typedef void (*diagFn)(llvm::SMDiagnostic const&, void*);
2928

30-
operator diagFn() const noexcept
31-
{
32-
return &diagFnImpl;
33-
}
29+
operator diagFn() const noexcept { return &diag; }
3430
};
3531

3632
} // mrdocs

0 commit comments

Comments
 (0)