Skip to content

Commit

Permalink
Merge branch 'main' into main_convergence
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron authored Oct 17, 2024
2 parents d2afb0f + 32b55f3 commit d2a7a57
Show file tree
Hide file tree
Showing 96 changed files with 4,710 additions and 2,426 deletions.
7 changes: 5 additions & 2 deletions clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

#include "UseInternalLinkageCheck.h"
#include "../utils/FileExtensionsUtils.h"
#include "../utils/LexerUtils.h"
#include "clang/AST/Decl.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersMacros.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/STLExtras.h"

using namespace clang::ast_matchers;
Expand Down Expand Up @@ -113,7 +116,7 @@ static constexpr StringRef Message =
void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("fn")) {
DiagnosticBuilder DB = diag(FD->getLocation(), Message) << "function" << FD;
SourceLocation FixLoc = FD->getTypeSpecStartLoc();
const SourceLocation FixLoc = FD->getInnerLocStart();
if (FixLoc.isInvalid() || FixLoc.isMacroID())
return;
if (FixMode == FixModeKind::UseStatic)
Expand All @@ -128,7 +131,7 @@ void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
return;

DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << VD;
SourceLocation FixLoc = VD->getTypeSpecStartLoc();
const SourceLocation FixLoc = VD->getInnerLocStart();
if (FixLoc.isInvalid() || FixLoc.isMacroID())
return;
if (FixMode == FixModeKind::UseStatic)
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM,
if (Location.isInvalid())
return {Token, Location};

auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
const auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
while (Location != StartOfFile) {
Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
(!SkipComments || !Token.is(tok::comment))) {
break;
}
if (Location == StartOfFile)
return {Token, Location};
Location = Location.getLocWithOffset(-1);
}
return {Token, Location};
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Changes in existing checks
<clang-tidy/checks/modernize/loop-convert>` check to fix false positive when
using loop variable in initializer of lambda capture.

- Improved :doc:`misc-use-internal-linkage
<clang-tidy/checks/misc/use-internal-linkage>` check to insert ``static`` keyword
before type qualifiers such as ``const`` and ``volatile``.

- Improved :doc:`modernize-min-max-use-initializer-list
<clang-tidy/checks/modernize/min-max-use-initializer-list>` check by fixing
a false positive when only an implicit conversion happened inside an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Violating the naming rules above results in undefined behavior.
int _g(); // disallowed in global namespace only

The check can also be inverted, i.e. it can be configured to flag any
identifier that is _not_ a reserved identifier. This mode is for use by e.g.
identifier that is *not* a reserved identifier. This mode is for use by e.g.
standard library implementors, to ensure they don't infringe on the user
namespace.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ void func_cpp_inc();
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
// CHECK-FIXES: static void func_cpp_inc();

int* func_cpp_inc_return_ptr();
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
// CHECK-FIXES: static int* func_cpp_inc_return_ptr();

const int* func_cpp_inc_return_const_ptr();
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_const_ptr'
// CHECK-FIXES: static const int* func_cpp_inc_return_const_ptr();

int const* func_cpp_inc_return_ptr_const();
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_ptr_const'
// CHECK-FIXES: static int const* func_cpp_inc_return_ptr_const();

int * const func_cpp_inc_return_const();
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'func_cpp_inc_return_const'
// CHECK-FIXES: static int * const func_cpp_inc_return_const();

volatile const int* func_cpp_inc_return_volatile_const_ptr();
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: function 'func_cpp_inc_return_volatile_const_ptr'
// CHECK-FIXES: static volatile const int* func_cpp_inc_return_volatile_const_ptr();

[[nodiscard]] void func_nodiscard();
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function 'func_nodiscard'
// CHECK-FIXES: {{\[\[nodiscard\]\]}} static void func_nodiscard();

#define NDS [[nodiscard]]
#define NNDS

NDS void func_nds();
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: function 'func_nds'
// CHECK-FIXES: NDS static void func_nds();

NNDS void func_nnds();
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'func_nnds'
// CHECK-FIXES: NNDS static void func_nnds();

#include "func_cpp.inc"

void func_h_inc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ T global_template;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: variable 'global_template'
// CHECK-FIXES: static T global_template;

int const* ptr_const_star;
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'ptr_const_star'
// CHECK-FIXES: static int const* ptr_const_star;

const int* const_ptr_star;
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'const_ptr_star'
// CHECK-FIXES: static const int* const_ptr_star;

const volatile int* const_volatile_ptr_star;
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: variable 'const_volatile_ptr_star'
// CHECK-FIXES: static const volatile int* const_volatile_ptr_star;

int gloabl_header;

extern int global_extern;
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Driver/Distro.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Distro {
UbuntuMantic,
UbuntuNoble,
UbuntuOracular,
UbuntuPlucky,
UnknownDistro
};

Expand Down Expand Up @@ -131,7 +132,7 @@ class Distro {
}

bool IsUbuntu() const {
return DistroVal >= UbuntuHardy && DistroVal <= UbuntuOracular;
return DistroVal >= UbuntuHardy && DistroVal <= UbuntuPlucky;
}

bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
Expand Down
37 changes: 29 additions & 8 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1863,27 +1863,48 @@ bool InitPop(InterpState &S, CodePtr OpPC) {
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitElem(InterpState &S, CodePtr OpPC, uint32_t Idx) {
const T &Value = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.peek<Pointer>().atIndex(Idx);
const Pointer &Ptr = S.Stk.peek<Pointer>();

if (Ptr.isUnknownSizeArray())
return false;
if (!CheckInit(S, OpPC, Ptr))

// In the unlikely event that we're initializing the first item of
// a non-array, skip the atIndex().
if (Idx == 0 && !Ptr.getFieldDesc()->isArray()) {
Ptr.initialize();
new (&Ptr.deref<T>()) T(Value);
return true;
}

const Pointer &ElemPtr = Ptr.atIndex(Idx);
if (!CheckInit(S, OpPC, ElemPtr))
return false;
Ptr.initialize();
new (&Ptr.deref<T>()) T(Value);
ElemPtr.initialize();
new (&ElemPtr.deref<T>()) T(Value);
return true;
}

/// The same as InitElem, but pops the pointer as well.
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t Idx) {
const T &Value = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.pop<Pointer>().atIndex(Idx);
const Pointer &Ptr = S.Stk.pop<Pointer>();
if (Ptr.isUnknownSizeArray())
return false;
if (!CheckInit(S, OpPC, Ptr))

// In the unlikely event that we're initializing the first item of
// a non-array, skip the atIndex().
if (Idx == 0 && !Ptr.getFieldDesc()->isArray()) {
Ptr.initialize();
new (&Ptr.deref<T>()) T(Value);
return true;
}

const Pointer &ElemPtr = Ptr.atIndex(Idx);
if (!CheckInit(S, OpPC, ElemPtr))
return false;
Ptr.initialize();
new (&Ptr.deref<T>()) T(Value);
ElemPtr.initialize();
new (&ElemPtr.deref<T>()) T(Value);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/Distro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static Distro::DistroType DetectLsbRelease(llvm::vfs::FileSystem &VFS) {
.Case("mantic", Distro::UbuntuMantic)
.Case("noble", Distro::UbuntuNoble)
.Case("oracular", Distro::UbuntuOracular)
.Case("plucky", Distro::UbuntuPlucky)
.Default(Distro::UnknownDistro);
return Version;
}
Expand Down
10 changes: 1 addition & 9 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,7 @@ DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,
ResourceClass ResClass) {
assert(getDeclBindingInfo(VD, ResClass) == nullptr &&
"DeclBindingInfo already added");
#ifndef NDEBUG
// Verify that existing bindings for this decl are stored sequentially
// and at the end of the BindingsList
auto I = DeclToBindingListIndex.find(VD);
if (I != DeclToBindingListIndex.end()) {
for (unsigned Index = I->getSecond(); Index < BindingsList.size(); ++Index)
assert(BindingsList[Index].Decl == VD);
}
#endif
assert(!hasBindingInfoForDecl(VD) || BindingsList.back().Decl == VD);
// VarDecl may have multiple entries for different resource classes.
// DeclToBindingListIndex stores the index of the first binding we saw
// for this decl. If there are any additional ones then that index
Expand Down
14 changes: 14 additions & 0 deletions clang/test/AST/ByteCode/placement-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ consteval auto ok4() {
}
static_assert(ok4() == 37);

consteval int ok5() {
int i;
new (&i) int[1]{1};

struct S {
int a; int b;
} s;
new (&s) S[1]{{12, 13}};

return 25;
// return s.a + s.b; FIXME: Broken in the current interpreter.
}
static_assert(ok5() == 25);

/// FIXME: Broken in both interpreters.
#if 0
consteval int ok5() {
Expand Down
9 changes: 7 additions & 2 deletions compiler-rt/lib/rtsan/rtsan_assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "rtsan/rtsan.h"
#include "rtsan/rtsan_context.h"
#include "rtsan/rtsan_diagnostics.h"
#include "rtsan/rtsan_stats.h"
#include "rtsan/rtsan_suppressions.h"

#include "sanitizer_common/sanitizer_stacktrace.h"
Expand All @@ -28,8 +29,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
if (context.InRealtimeContext() && !context.IsBypassed()) {
ScopedBypass sb{context};

if (IsFunctionSuppressed(info.func_name))
if (IsFunctionSuppressed(info.func_name)) {
IncrementSuppressedCount();
return;
}

__sanitizer::BufferedStackTrace stack;

Expand All @@ -38,8 +41,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
stack.Unwind(info.pc, info.bp, nullptr,
__sanitizer::common_flags()->fast_unwind_on_fatal);

if (IsStackTraceSuppressed(stack))
if (IsStackTraceSuppressed(stack)) {
IncrementSuppressedCount();
return;
}

OnViolation(stack, info);
}
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct Flags {
Type Name{DefaultValue};
#include "rtsan_flags.inc"
#undef RTSAN_FLAG

bool ContainsSuppresionFile() { return suppressions[0] != '\0'; }
};

extern Flags flags_data;
Expand Down
25 changes: 19 additions & 6 deletions compiler-rt/lib/rtsan/rtsan_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,48 @@
//===----------------------------------------------------------------------===//

#include "rtsan/rtsan_stats.h"
#include "rtsan/rtsan_flags.h"

#include "sanitizer_common/sanitizer_atomic.h"
#include "sanitizer_common/sanitizer_common.h"

using namespace __sanitizer;
using namespace __rtsan;

static atomic_uint32_t rtsan_total_error_count{0};
static atomic_uint32_t rtsan_unique_error_count{0};
static atomic_uint32_t total_error_count{0};
static atomic_uint32_t unique_error_count{0};
static atomic_uint32_t suppressed_count{0};

void __rtsan::IncrementTotalErrorCount() {
atomic_fetch_add(&rtsan_total_error_count, 1, memory_order_relaxed);
atomic_fetch_add(&total_error_count, 1, memory_order_relaxed);
}

void __rtsan::IncrementUniqueErrorCount() {
atomic_fetch_add(&rtsan_unique_error_count, 1, memory_order_relaxed);
atomic_fetch_add(&unique_error_count, 1, memory_order_relaxed);
}

static u32 GetTotalErrorCount() {
return atomic_load(&rtsan_total_error_count, memory_order_relaxed);
return atomic_load(&total_error_count, memory_order_relaxed);
}

static u32 GetUniqueErrorCount() {
return atomic_load(&rtsan_unique_error_count, memory_order_relaxed);
return atomic_load(&unique_error_count, memory_order_relaxed);
}

void __rtsan::IncrementSuppressedCount() {
atomic_fetch_add(&suppressed_count, 1, memory_order_relaxed);
}

static u32 GetSuppressedCount() {
return atomic_load(&suppressed_count, memory_order_relaxed);
}

void __rtsan::PrintStatisticsSummary() {
ScopedErrorReportLock l;
Printf("RealtimeSanitizer exit stats:\n");
Printf(" Total error count: %u\n", GetTotalErrorCount());
Printf(" Unique error count: %u\n", GetUniqueErrorCount());

if (flags().ContainsSuppresionFile())
Printf(" Suppression count: %u\n", GetSuppressedCount());
}
1 change: 1 addition & 0 deletions compiler-rt/lib/rtsan/rtsan_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace __rtsan {

void IncrementTotalErrorCount();
void IncrementUniqueErrorCount();
void IncrementSuppressedCount();

void PrintStatisticsSummary();

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/rtsan/rtsan_suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void __rtsan::InitializeSuppressions() {
CHECK_EQ(nullptr, suppression_ctx);

// We will use suppression_ctx == nullptr as an early out
if (flags().suppressions[0] == '\0')
if (!flags().ContainsSuppresionFile())
return;

suppression_ctx = new (suppression_placeholder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ TEST(SanitizerCommon, PthreadDestructorIterations) {

TEST(SanitizerCommon, IsAccessibleMemoryRange) {
const int page_size = GetPageSize();
uptr mem = (uptr)mmap(0, 3 * page_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
InternalMmapVector<char> buffer(3 * page_size);
uptr mem = reinterpret_cast<uptr>(buffer.data());
// Protect the middle page.
mprotect((void *)(mem + page_size), page_size, PROT_NONE);
EXPECT_TRUE(IsAccessibleMemoryRange(mem, page_size - 1));
Expand All @@ -78,8 +78,6 @@ TEST(SanitizerCommon, IsAccessibleMemoryRange) {
EXPECT_TRUE(IsAccessibleMemoryRange(mem + 2 * page_size, page_size));
EXPECT_FALSE(IsAccessibleMemoryRange(mem, 3 * page_size));
EXPECT_FALSE(IsAccessibleMemoryRange(0x0, 2));

munmap((void *)mem, 3 * page_size);
}

} // namespace __sanitizer
Expand Down
Loading

0 comments on commit d2a7a57

Please sign in to comment.