Skip to content
Open
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
12 changes: 8 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ jobs:
cxxflags: ${{ matrix.cxxflags }} ${{ env.BOOTSTRAP_CXXFLAGS }}
ldflags: ${{ env.BOOTSTRAP_LDFLAGS }}
generator: Ninja
# Build under build/mrdocs, a sibling of build/third-party, so the
# coverage and flamegraph steps below scan only our own artifacts
# and never the third-party install tree.
build-dir: build/mrdocs
build-type: ${{ matrix.build-type }}
install-prefix: .local
export-compile-commands: true
Expand All @@ -145,15 +149,15 @@ jobs:
with:
name: ${{ matrix.mrdocs-release-package-artifact }}
path: |
build/packages
!build/packages/_CPack_Packages
build/mrdocs/packages
!build/mrdocs/packages/_CPack_Packages
retention-days: 1

- name: FlameGraph
uses: alandefreitas/cpp-actions/flamegraph@v1.9.5
if: matrix.time-trace
with:
build-dir: build
build-dir: build/mrdocs
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Process Coverage
Expand All @@ -162,7 +166,7 @@ jobs:
uses: alandefreitas/cpp-actions/process-coverage@v1.9.5
with:
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }}
build-dir: build
build-dir: build/mrdocs
html-report: true
codecov-token: ${{ secrets.CODECOV_TOKEN }}
codecov-flags: cpp
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ jobs:
main-entry-factors: |
clang Coverage
latest-factors: |
clang UBSan
clang UBSan MSan ASan
factors: |
gcc UBSan
clang ASan MSan
apple-clang UBSan ASan
build-types: |
gcc: Release
Expand Down Expand Up @@ -82,7 +81,7 @@ jobs:
llvm-runtimes: {{{select (ine use-libcxx 'true') libcxx-runtimes ""}}}

# LLVM build configuration
llvm-hash: dc4cef81d47c7bc4a3c4d58fbacf8a6359683fae
llvm-hash: 77e43ec11cd8fbe1de491118b54de9bba94510a8
llvm-short-hash: {{{substr llvm-hash 0 7}}}
llvm-preset-build-type: {{{lowercase build-type}}}
llvm-preset-os: {{select (ieq os 'windows') "win" "unix"}}
Expand Down
24 changes: 1 addition & 23 deletions share/mrdocs/headers/libc-stubs/new.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,7 @@
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_NEW_H

#if defined(_LIBCPP_ABI_VCRUNTIME)
namespace std {
enum class align_val_t : size_t {};
struct nothrow_t { explicit nothrow_t() = default; };
extern const std::nothrow_t nothrow;
}

// Replaceable allocation functions
void* operator new ( std::size_t count );
void* operator new[]( std::size_t count );
void* operator new ( std::size_t count, std::align_val_t al );
void* operator new[]( std::size_t count, std::align_val_t al );

// Replaceable non-throwing allocation functions
void* operator new ( std::size_t count, const std::nothrow_t& tag );
void* operator new[]( std::size_t count, const std::nothrow_t& tag );
void* operator new ( std::size_t count, std::align_val_t al,
const std::nothrow_t& tag ) noexcept;
void* operator new[]( std::size_t count, std::align_val_t al,
const std::nothrow_t& tag ) noexcept;

// Non-allocating placement allocation functions
void* operator new ( std::size_t count, void* ptr );
void* operator new[]( std::size_t count, void* ptr );
#include <vcruntime_new.h>
Comment thread
alandefreitas marked this conversation as resolved.
#endif

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_NEW_H
2 changes: 2 additions & 0 deletions share/mrdocs/headers/libc-stubs/stdalign.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_STDALIGN_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_STDALIGN_H

#if !defined __cplusplus
// Convenience macros for alignment
#define alignas _Alignas
#define alignof _Alignof
#endif

// Macro constants indicating the presence of alignment features
#define __alignas_is_defined 1
Expand Down
2 changes: 2 additions & 0 deletions share/mrdocs/headers/libc-stubs/stdbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_STDBOOL_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_STDBOOL_H

#if !defined __cplusplus
// Convenience macros for boolean values
#define bool _Bool
#define true 1
#define false 0
#endif

// Macro constant indicating the presence of boolean features
#define __bool_true_false_are_defined 1
Expand Down
2 changes: 2 additions & 0 deletions share/mrdocs/headers/libc-stubs/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx);
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts);
void cnd_destroy(cnd_t *cond);

#if !defined __cplusplus
// Thread-local storage
#define thread_local _Thread_local
#endif

typedef void (*tss_dtor_t)(void *);
typedef struct {
Expand Down
38 changes: 38 additions & 0 deletions share/mrdocs/headers/libc-stubs/vcruntime_new.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_VCRUNTIME_NEW_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_VCRUNTIME_NEW_H

namespace std {
enum class align_val_t : size_t {};
struct nothrow_t { explicit nothrow_t() = default; };
extern const std::nothrow_t nothrow;
}

// Replaceable allocation functions
void* operator new ( std::size_t count );
void* operator new[]( std::size_t count );
void* operator new ( std::size_t count, std::align_val_t al );
void* operator new[]( std::size_t count, std::align_val_t al );

// Replaceable non-throwing allocation functions
void* operator new ( std::size_t count, const std::nothrow_t& tag );
void* operator new[]( std::size_t count, const std::nothrow_t& tag );
void* operator new ( std::size_t count, std::align_val_t al,
const std::nothrow_t& tag ) noexcept;
void* operator new[]( std::size_t count, std::align_val_t al,
const std::nothrow_t& tag ) noexcept;

// Non-allocating placement allocation functions
void* operator new ( std::size_t count, void* ptr );
void* operator new[]( std::size_t count, void* ptr );

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_VCRUNTIME_NEW_H
2 changes: 1 addition & 1 deletion src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include <clang/AST/RawCommentList.h>
#include <clang/AST/TypeVisitor.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Index/USRGeneration.h>
#include <clang/Lex/Lexer.h>
#include <clang/Sema/Lookup.h>
#include <clang/Sema/Sema.h>
#include <clang/Sema/Template.h>
#include <clang/UnifiedSymbolResolution/USRGeneration.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/Support/Error.h>
#include <llvm/Support/Process.h>
Expand Down
92 changes: 65 additions & 27 deletions src/lib/AST/ClangHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2023 Krystian Stasiowski (sdkrystian@gmail.com)
// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand All @@ -14,20 +15,26 @@
#include <mrdocs/Support/Assert.hpp>
#include <mrdocs/Support/Report.hpp>
#include <clang/Driver/Driver.h>
#include <clang/Index/USRGeneration.h>
#include <clang/Sema/EnterExpressionEvaluationContext.h>
#include <clang/Sema/Template.h>
#include <clang/UnifiedSymbolResolution/USRGeneration.h>
#include <llvm/Option/ArgList.h>
#include <ranges>

namespace mrdocs {

// Ported from Clang's file-local static `SubstituteConstraintExpressionWithoutSatisfaction`
// in clang/lib/Sema/SemaConcept.cpp. No public header exposes it, and the public
// `Sema::AreConstraintExpressionsEqual` returns only a bool, not the substituted
// expression MrDocs needs, so we vendor a copy. Synced to the pinned revision
// 77e43ec1; re-diff against that file on each LLVM bump.
clang::Expr const*
SubstituteConstraintExpressionWithoutSatisfaction(
clang::Sema &S, const clang::Sema::TemplateCompareNewDeclInfo &DeclInfo,
clang::Expr const* ConstrExpr)
{
clang::MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
DeclInfo.getDecl(), DeclInfo.getDeclContext(), /*Final=*/false,
/*Innermost=*/std::nullopt,
/*RelativeToPrimary=*/true,
/*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
Expand All @@ -38,31 +45,48 @@ SubstituteConstraintExpressionWithoutSatisfaction(
return ConstrExpr;
}

// Clang's own `AreConstraintExpressionsEqual` wraps the calls to this
// helper in a `SFINAETrap`. MrDocs invokes the helper directly, so the trap
// lives here instead: it traps substitution errors and supplies the SFINAE
// context that `SubstConstraintExprWithoutSatisfaction` expects on the
// instantiation stack.
clang::Sema::SFINAETrap const SFINAE(S, /*AccessCheckingSFINAE=*/false);

clang::Sema::InstantiatingTemplate Inst(
S, DeclInfo.getLocation(),
clang::Sema::InstantiatingTemplate::ConstraintNormalization{},
const_cast<clang::NamedDecl *>(DeclInfo.getDecl()), clang::SourceRange{});
if (Inst.isInvalid())
{
return nullptr;
}

// Set up a dummy 'instantiation' scope in the case of reference to function
// parameters that the surrounding function hasn't been instantiated yet. Note
// this may happen while we're comparing two templates' constraint
// equivalence.
clang::LocalInstantiationScope ScopeForParameters(S);
if (auto *FD = DeclInfo.getDecl()->getAsFunction())
{
for (auto *PVD : FD->parameters())
std::optional<clang::LocalInstantiationScope> ScopeForParameters;
if (clang::NamedDecl const* ND = DeclInfo.getDecl();
ND && ND->isFunctionOrFunctionTemplate())
{
ScopeForParameters.emplace(S, /*CombineWithOuterScope=*/true);
clang::FunctionDecl const* FD = ND->getAsFunction();
if (clang::FunctionTemplateDecl* Template =
FD->getDescribedFunctionTemplate();
Template && Template->getInstantiatedFromMemberTemplate())
{
ScopeForParameters.InstantiatedLocal(PVD, PVD);
FD = Template->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
}
for (auto* PVD : FD->parameters())
{
if (ScopeForParameters->getInstantiationOfIfExists(PVD))
{
continue;
}
if (!PVD->isParameterPack())
{
ScopeForParameters->InstantiatedLocal(PVD, PVD);
continue;
}
// Map the parameter pack to a size-of-1 argument so its canonical
// type is used when comparing redeclarations for equivalence.
ScopeForParameters->MakeInstantiatedLocalArgPack(PVD);
ScopeForParameters->InstantiatedLocalPackArg(PVD, PVD);
}
}

Optional<clang::Sema::CXXThisScopeRAII> ThisScope;
std::optional<clang::Sema::CXXThisScopeRAII> ThisScope;

// See TreeTransform::RebuildTemplateSpecializationType. A context scope is
// essential for having an injected class as the canonical type for a template
Expand All @@ -71,13 +95,27 @@ SubstituteConstraintExpressionWithoutSatisfaction(
// template specializations can be profiled to the same value, which makes it
// possible that e.g. constraints involving C<Class<T>> and C<Class> are
// perceived identical.
Optional<clang::Sema::ContextRAII> ContextScope;
if (auto *RD = dyn_cast<clang::CXXRecordDecl>(DeclInfo.getDeclContext()))
{
ThisScope.emplace(S, const_cast<clang::CXXRecordDecl *>(RD), clang::Qualifiers());
ContextScope.emplace(S, const_cast<clang::DeclContext *>(cast<clang::DeclContext>(RD)),
/*NewThisContext=*/false);
}
std::optional<clang::Sema::ContextRAII> ContextScope;
clang::DeclContext const* DC = [&] {
if (!DeclInfo.getDecl())
{
return DeclInfo.getDeclContext();
}
return DeclInfo.getDecl()->getFriendObjectKind()
? DeclInfo.getLexicalDeclContext()
: DeclInfo.getDeclContext();
}();
if (auto* RD = dyn_cast<clang::CXXRecordDecl>(DC))
{
ThisScope.emplace(
S, const_cast<clang::CXXRecordDecl*>(RD), clang::Qualifiers());
ContextScope.emplace(
S, const_cast<clang::DeclContext*>(cast<clang::DeclContext>(RD)),
/*NewThisContext=*/false);
}
clang::EnterExpressionEvaluationContext UnevaluatedContext(
S, clang::Sema::ExpressionEvaluationContext::Unevaluated,
clang::Sema::ReuseLambdaContextDecl);
clang::ExprResult SubstConstr = S.SubstConstraintExprWithoutSatisfaction(
const_cast<clang::Expr *>(ConstrExpr), MLTAL);
if (SFINAE.hasErrorOccurred() || !SubstConstr.isUsable())
Expand Down Expand Up @@ -475,15 +513,15 @@ isStaticFileLevelMember(clang::Decl const* D)
clang::RawComment const*
getDocumentation(clang::Decl const* D)
{
clang::RawComment const* RC =
D->getASTContext().getRawCommentForDeclNoCache(D);
clang::ASTContext const& ctx = D->getASTContext();
clang::RawComment const* RC = ctx.getRawCommentNoCache(D);
if (!RC)
{
auto const* TD = dyn_cast<clang::TemplateDecl>(D);
MRDOCS_CHECK_OR(TD, nullptr);
clang::NamedDecl const* ND = TD->getTemplatedDecl();
MRDOCS_CHECK_OR(ND, nullptr);
RC = ND->getASTContext().getRawCommentForDeclNoCache(ND);
RC = ctx.getRawCommentNoCache(ND);
}
return RC;
}
Expand Down
10 changes: 0 additions & 10 deletions src/lib/AST/MissingSymbolSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,6 @@ class CollectingDiagConsumer : public clang::DiagnosticConsumer {

Downstream_->EndSourceFile();
}


void
finish() override
{
if (Downstream_)
{
Downstream_->finish();
}
}
};

} // namespace mrdocs
Expand Down
Loading