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
9 changes: 9 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ jobs:
build-dir: build
github-token: ${{ secrets.GITHUB_TOKEN }}

# The coverage step scans build/ for *.profraw, which also sweeps up
# the committed *.profraw test fixtures in LLVM's extracted source
# tree; their older format fails the llvm-profdata merge. The
# process-coverage action can't exclude a subdirectory from that
# scan, so drop those foreign files first.
- name: Prune third-party profraw
if: matrix.coverage
run: find build/third-party -name '*.profraw' -delete

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What’s this profraw issue? The explanation is more descriptive than explanatory of the motivation of the command. It seems to me like if this is happening and coverage is globing the wrong directory, that’s what should be fixed instead of a second workaround to accommodate the first mistake.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The issue is that the coverage step scans build/ for *.profraw, which happens to include the *.profraw test fixtures in the LLVM extracted source tree; but they are in an older format, which makes the llvm-profdata merge fail. I'm not sure why this issue didn't occur when the cache was cold, the first time. Yes, this would better be fixed in the action.


- name: Process Coverage
id: process-coverage
if: matrix.coverage
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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Interesting. Is this something being fixed in passing or do we have something about the new version that interacts with the libc stubs? In fact, I would have this question about all other changes to the libc stubs. It's unexpected to me that they interacted in an LLVM bump.

#endif

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

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

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

// Convenience macros for boolean values
#if !defined __cplusplus
#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
3 changes: 2 additions & 1 deletion share/mrdocs/headers/libc-stubs/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ 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);

// Thread-local storage
#if !defined __cplusplus
#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
87 changes: 60 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,8 +15,9 @@
#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>

Expand All @@ -27,7 +29,7 @@ SubstituteConstraintExpressionWithoutSatisfaction(
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 +40,48 @@ SubstituteConstraintExpressionWithoutSatisfaction(
return ConstrExpr;
}

// Clang's own `AreConstraintExpressionsEqual` wraps the calls to this
// helper in an `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 +90,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 +508,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
Loading