Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f3566c
[Test][clang-repl]Keep value names in clang-repl pragma-optimize.cpp …
jsji Oct 24, 2026
5916210
[mlir] Find the pattern dump root only when IR debugging is enabled (…
Hardcode84 Oct 24, 2026
127d4f0
[clang-tidy] Don't suggest const on `std::moved` locals in templates …
daniel-petrovic Oct 24, 2026
bfe0941
[mlir][linalg] Handle `DropPadUnitDims` when padding value is defined…
FedericoBruzzone Oct 24, 2026
a98c5c2
[SelectionDAG] Implement SDTCisSameAs in verifyNode. (#235157)
topperc Oct 24, 2026
45e57b7
[TargetLowering] Don't call SignBitIsZero for ABDS in expandABD. (#23…
topperc Oct 24, 2026
e339ea8
[DAGCombiner] Delay calls to willNotOverflow and SignBitIsZero in fol…
topperc Oct 24, 2026
cfe60cf
[RISCV] Use vector getConstant. NFC (#235152)
topperc Oct 24, 2026
3736dfe
[SelectionDAG][RISCV][X86] Keep jump table range checks with cf-prote…
topperc Oct 24, 2026
7bcef9f
RegAlloc: Only def the subregister regunits of a failed subregister d…
arsenm Oct 24, 2026
e8eba6e
AMDGPU: Don't reserve the implicit buffer pointer with architected fl…
arsenm Oct 24, 2026
60c2f3e
[runtimes][Fortran] No introspection in bootstrapping build (#234424)
Meinersbur Oct 24, 2026
625d950
[SandboxVec] Remove empty test directory (NFC) (#235015)
vporpo Oct 24, 2026
9cf173d
CodeGen: Consolidate MachinePipeliner controls (#235311)
arsenm Oct 24, 2026
f99a018
[CodeGen] Move BasicBlockMatchingAndInference options to CodeGenOptio…
rlavaee Oct 24, 2026
34379c8
[mlir] Skip uniquer locks when a context starts without threading (#2…
aobolensk Oct 24, 2026
4f2421f
[TLI][SimplifyLibCalls] Accept [2 x iN] return type for __size_returi…
snehasish Oct 24, 2026
f45474e
Revert "[SelectionDAG] Implement SDTCisSameAs in verifyNode." (#235329)
topperc Oct 24, 2026
ee824d2
[clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) (#23…
kazutakahirata Oct 24, 2026
de39e75
[IR] Remove unused GEPOperator::countNonConstantIndices (NFC) (#235233)
kazutakahirata Oct 24, 2026
c0815b9
[ARM] Replace reg in preheader when reverting WhileLoopStartLR (#229754)
davemgreen Oct 24, 2026
1c39076
[flang][acc] Name deviceptr objects on the exit of a local declare (#…
wangzpgi Oct 24, 2026
e312add
[libc] Modify NaN/payload functions for emulated float128 type (#221946)
Popie52 Oct 24, 2026
e422530
[Driver][SYCL] Link libclang_rt.builtins.bc for spirv64 at compile ti…
srividya-sundaram Oct 24, 2026
406dbc2
[VPlan] Drop poison-gen attributes & metadata on replicated clones. (…
fhahn Oct 24, 2026
8f8e41f
[VPlan] Simplify epilogue connection (NFC). (#235344)
fhahn Oct 24, 2026
78a9c8d
[CIR][CUDA] Add host-side surface registration support (#225146)
Siya-05 Oct 24, 2026
a48ab42
[Flang][test] Use x86 triple (#235354)
Meinersbur Oct 24, 2026
b1db344
[WindowScheduler] Preserve loop-carried memory dependences (#231364)
iajbar Oct 24, 2026
25385ba
[Passes] Make runCodeGenPipeline take raw_pwrite_stream for DwoOS (#2…
boomanaiden154 Oct 24, 2026
5a3a7e3
merge main into amd-staging
z1-cciauto Oct 24, 2026
a16800b
Revert "[mlir] Skip uniquer locks when a context starts without threa…
ronlieb Oct 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 27 additions & 3 deletions clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
}
}

static bool isStdMoveOperandInTemplate(const VarDecl *Variable,
const FunctionDecl *Func,
ASTContext &Context) {
if (Func->isTemplateInstantiation())
if (const Stmt *Body = Func->getBody()) {
// Match on the instantiated body where `std::move` is resolved to a
// concrete function and the argument references the instantiated
// variable.
const auto Moves =
match(stmt(forEachDescendant(
callExpr(callee(functionDecl(hasName("std::move"))),
hasArgument(0, ignoringParenImpCasts(declRefExpr(
to(equalsNode(Variable)))))))),
*Body, Context);
return !Moves.empty();
}
return false;
}

static void addConstFixits(const DiagnosticBuilder &Diag,
const VarDecl *Variable,
const FunctionDecl *Function,
Expand Down Expand Up @@ -255,9 +274,6 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
/// dependent. Variables like 'int x = 42;' in a template that can become
/// const emit multiple warnings otherwise.
bool IsNormalVariableInTemplate = Function->isTemplateInstantiation();
if (IsNormalVariableInTemplate &&
TemplateDiagnosticsCache.contains(Variable->getBeginLoc()))
return;

VariableCategory VC = VariableCategory::Value;
const QualType VT = Variable->getType();
Expand All @@ -269,6 +285,14 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
ArrayT && ArrayT->getElementType()->isPointerType())
VC = VariableCategory::Pointer;

if (IsNormalVariableInTemplate && VC != VariableCategory::Pointer &&
isStdMoveOperandInTemplate(Variable, Function, *Result.Context))
return;

if (IsNormalVariableInTemplate &&
TemplateDiagnosticsCache.contains(Variable->getBeginLoc()))
return;

const auto CheckValue = [&]() {
// Offload const-analysis to utility function.
if (isMutated(Variable, LocalScope, Function, Result.Context))
Expand Down
8 changes: 6 additions & 2 deletions clang-tools-extra/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,14 @@ infrastructure are described first, followed by tool-specific sections.

- No longer diagnoses variables declared with `decltype(auto)`, where the
suggested `const` does not compile.

- No longer diagnoses parameters of `main`, whose signature is fixed by the
standard.

- No longer diagnoses variables used as operands of `std::move` in template
instantiations, where the suggested `const` would break the move for
instantiations with real move semantics.

- Fixed an infinite loop in {doc}`misc-multiple-inheritance
<clang-tidy/checks/misc/multiple-inheritance>` when checking a class that
inherits from itself or has a circular inheritance graph.
Expand Down Expand Up @@ -429,7 +433,7 @@ infrastructure are described first, followed by tool-specific sections.
- Ignored preprocessor directives such as `#endif` that appear immediately
before an enum's closing brace, which previously produced a false positive
and a fix-it that inserted a comma after the directive.

- Fixed a false positive on empty brace initializers of types with default
member initializers.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// RUN: misc-const-correctness.TransformPointersAsValues: false} \
// RUN: }" -- -fno-delayed-template-parsing

#include <string>
#include <utility>

template <typename T>
void type_dependent_variables() {
T value = 42;
Expand All @@ -27,6 +30,23 @@ void instantiate_template_cases() {
type_dependent_variables<float>();
}

namespace gh225395 {

template <typename T> void my_swap(T &t1, T &t2) {
auto tmp = std::move(t1);
t1 = std::move(t2);
t2 = std::move(tmp);
}
void instantiate() {
std::string a;
std::string b;
my_swap(a, b);
int x = 0;
int y = 0;
my_swap(x, y);
}
} // namespace gh225395

namespace gh57297{
// The expression to check may not be the dependent operand in a dependent
// operator.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ class CXXCtorInitializer final {
/// Returns the declarator information for a base class or delegating
/// initializer.
TypeSourceInfo *getTypeSourceInfo() const {
return Initializee.dyn_cast<TypeSourceInfo *>();
return dyn_cast<TypeSourceInfo *>(Initializee);
}

/// If this is a member initializer, returns the declaration of the
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclFriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class FriendDecl : public Decl {
/// If this friend declaration doesn't name a type, return the inner
/// declaration.
virtual NamedDecl *getFriendDecl() const {
return Friend.dyn_cast<NamedDecl *>();
return dyn_cast<NamedDecl *>(Friend);
}

/// Retrieves the location of the '...', if present.
Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class DefaultArgStorage {

static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
if (auto *Prev = dyn_cast<ParmDecl *>(Storage.ValueOrInherited))
Parm = Prev;
assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) &&
"should only be one level of indirection");
Expand All @@ -337,19 +337,19 @@ class DefaultArgStorage {
/// default argument is visible.
ArgType get() const {
const DefaultArgStorage *Storage = this;
if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
if (const auto *Prev = dyn_cast<ParmDecl *>(ValueOrInherited))
Storage = &Prev->getDefaultArgStorage();
if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
if (const auto *C = dyn_cast<Chain *>(Storage->ValueOrInherited))
return C->Value;
return cast<ArgType>(Storage->ValueOrInherited);
}

/// Get the parameter from which we inherit the default argument, if any.
/// This is the parameter on which the default argument was actually written.
const ParmDecl *getInheritedFrom() const {
if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
if (const auto *D = dyn_cast<ParmDecl *>(ValueOrInherited))
return D;
if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
if (const auto *C = dyn_cast<Chain *>(ValueOrInherited))
return C->PrevDeclWithDefaultArg;
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2713,11 +2713,11 @@ class PseudoDestructorTypeStorage {
PseudoDestructorTypeStorage(TypeSourceInfo *Info);

TypeSourceInfo *getTypeSourceInfo() const {
return Type.dyn_cast<TypeSourceInfo *>();
return dyn_cast<TypeSourceInfo *>(Type);
}

const IdentifierInfo *getIdentifier() const {
return Type.dyn_cast<const IdentifierInfo *>();
return dyn_cast<const IdentifierInfo *>(Type);
}

SourceLocation getLocation() const { return Location; }
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/ExternalASTSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ struct LazyGenerationalDeclPtr {

/// Set the value of this pointer, in the current generation.
void set(Decl *NewValue) {
if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
if (auto *LazyVal = dyn_cast<LazyData *>(Value)) {
LazyVal->LastValue = NewValue;
return;
}
Expand All @@ -480,7 +480,7 @@ struct LazyGenerationalDeclPtr {

/// Get the value of this pointer, updating its owner if necessary.
Decl *get(const Decl *O) {
if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
if (auto *LazyVal = dyn_cast<LazyData *>(Value)) {
if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
LazyVal->ExternalSource->CompleteRedeclChain(O);
Expand All @@ -492,7 +492,7 @@ struct LazyGenerationalDeclPtr {

/// Get the most recently computed value of this pointer without updating it.
Decl *getNotUpdated() const {
if (auto *LazyVal = Value.template dyn_cast<LazyData *>())
if (auto *LazyVal = dyn_cast<LazyData *>(Value))
return LazyVal->LastValue;
return cast<Decl *>(Value);
}
Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ def warn_drv_fraw_string_literals_in_cxx11 : Warning<
"ignoring '-f%select{no-|}0raw-string-literals', which is only valid for C and C++ standards before C++11">,
InGroup<UnusedCommandLineArgument>;

def err_drv_libclc_not_found : Error<"no libclc library '%0' found in the clang resource directory">;
def err_drv_device_lib_not_found : Error<
"no %select{libclc|compiler-rt builtins bitcode}0 library '%1' found in the "
"clang resource directory%select{|; build compiler-rt with SPIR-V support or "
"pass '--no-offloadlib' to compile without it}0">;

def err_drv_invalid_malign_branch_EQ : Error<
"invalid argument '%0' to -malign-branch=; each element must be one of: %1">;
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRCUDAAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def CIR_CUDAVarRegistrationInfoAttr : CIR_Attr<"CUDAVarRegistrationInfo", "cu.va
// handleVarRegistration via hasAttr<HIPManagedAttr>().
"bool":$isExtern,
"bool":$isConstant,
"bool":$isManaged
"bool":$isManaged,
"int32_t":$surfTexType
);

let hasCustomAssemblyFormat = 1;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class Driver {
// TODO: Much of what getFinalPhase returns are not actually true compiler
// modes. Fold this functionality into Types::getCompilationPhases and
// handleArguments.
phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
phases::ID getFinalPhase(const llvm::opt::ArgList &Args,
llvm::opt::Arg **FinalPhaseArg = nullptr) const;

llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/PreprocessingRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Token;
/// The definition of the macro being expanded. May return null if
/// this is a builtin macro.
MacroDefinitionRecord *getDefinition() const {
return NameOrDef.dyn_cast<MacroDefinitionRecord *>();
return dyn_cast<MacroDefinitionRecord *>(NameOrDef);
}

// Implement isa/cast/dyncast/etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ class CallEvent {

/// Returns the declaration of the function or method that will be
/// called. May be null.
virtual const Decl *getDecl() const {
return Origin.dyn_cast<const Decl *>();
}
virtual const Decl *getDecl() const { return dyn_cast<const Decl *>(Origin); }

bool isForeign() const {
assert(Foreign && "Foreign must be set before querying");
Expand Down Expand Up @@ -260,7 +258,7 @@ class CallEvent {
/// Returns the expression whose value will be the result of this call.
/// Null if and only if 'this' is a CXXDestructorCall.
virtual const Expr *getOriginExpr() const {
return Origin.dyn_cast<const Expr *>();
return dyn_cast<const Expr *>(Origin);
}

/// Returns the number of arguments (explicit and implicit).
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ Expr *VarDecl::getInit() {
}

Stmt **VarDecl::getInitAddress() {
if (auto *ES = Init.dyn_cast<EvaluatedStmt *>())
if (auto *ES = dyn_cast<EvaluatedStmt *>(Init))
return ES->Value.getAddressOfPointer(getASTContext().getExternalSource());

return Init.getAddrOfPtr1();
Expand Down
34 changes: 24 additions & 10 deletions clang/lib/CIR/CodeGen/CIRGenCUDANV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ class CIRGenNVCUDARuntime : public CIRGenCUDARuntime {
builder.getContext(),
getDeviceSideName(cast<NamedDecl>(vd)),
cir::CUDADeviceVarKind::Variable, isExtern, isConstant,
vd->hasAttr<HIPManagedAttr>()));
vd->hasAttr<HIPManagedAttr>(),
/*surfTexType=*/0));
deviceVars.push_back({
var,
vd,
cir::CUDADeviceVarKind::Variable,
});
}

void registerDeviceSurf(const VarDecl *vd, cir::GlobalOp &var,
bool isExtern) {
void registerDeviceSurf(const VarDecl *vd, cir::GlobalOp &var, bool isExtern,
int32_t surfaceType) {
auto &builder = cgm.getBuilder();

var->setAttr(cir::CUDAVarRegistrationInfoAttr::getMnemonic(),
Expand All @@ -118,7 +119,7 @@ class CIRGenNVCUDARuntime : public CIRGenCUDARuntime {
getDeviceSideName(cast<NamedDecl>(vd)),
cir::CUDADeviceVarKind::Surface, isExtern,
/*isConstant=*/false,
/*isManaged=*/false));
/*isManaged=*/false, surfaceType));

deviceVars.push_back({
var,
Expand All @@ -136,7 +137,8 @@ class CIRGenNVCUDARuntime : public CIRGenCUDARuntime {
getDeviceSideName(cast<NamedDecl>(vd)),
cir::CUDADeviceVarKind::Texture, isExtern,
/*isConstant=*/false,
/*isManaged=*/false));
/*isManaged=*/false,
/*surfTexType=*/0));

deviceVars.push_back({
var,
Expand Down Expand Up @@ -450,14 +452,15 @@ void CIRGenNVCUDARuntime::internalizeDeviceSideVar(
// counterparts. It's not clear yet whether it's nvcc's bug or
// a feature, but we've got to do the same for compatibility.
if (d->hasAttr<CUDADeviceAttr>() || d->hasAttr<CUDAConstantAttr>() ||
d->hasAttr<CUDASharedAttr>()) {
d->hasAttr<CUDASharedAttr>() ||
d->getType()->isCUDADeviceBuiltinSurfaceType() ||
d->getType()->isCUDADeviceBuiltinTextureType()) {
linkage = cir::GlobalLinkageKind::InternalLinkage;
}

if (d->getType()->isCUDADeviceBuiltinSurfaceType() ||
d->getType()->isCUDADeviceBuiltinTextureType())
if (d->getType()->isCUDADeviceBuiltinTextureType())
cgm.errorNYI(d->getSourceRange(),
"internalizeDeviceSideVar: CUDA Surface/Texture support");
"internalizeDeviceSideVar: CUDA Texture support");
}

std::string CIRGenNVCUDARuntime::getDeviceSideName(const NamedDecl *nd) {
Expand Down Expand Up @@ -518,8 +521,19 @@ void CIRGenNVCUDARuntime::handleVarRegistration(const VarDecl *vd,
} else if (vd->getType()->isCUDADeviceBuiltinSurfaceType()) {
// Builtin surfaces and their template arguments are also registered
// with CUDA runtime.
const auto *td = cast<ClassTemplateSpecializationDecl>(
vd->getType()->castAsCXXRecordDecl());
const TemplateArgumentList &args = td->getTemplateArgs();

assert(args.size() == 2 &&
"Unexpected number of template arguments of CUDA device "
"builtin surface type.");

llvm::APSInt surfaceType = args[1].getAsIntegral();

if (!vd->hasExternalStorage())
registerDeviceSurf(vd, var, !vd->hasDefinition());
registerDeviceSurf(vd, var, !vd->hasDefinition(),
surfaceType.getSExtValue());

} else if (vd->getType()->isCUDADeviceBuiltinTextureType()) {
// Builtin textures and their template arguments are also registered
Expand Down
10 changes: 8 additions & 2 deletions clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ void CUDAVarRegistrationInfoAttr::print(AsmPrinter &p) const {
p << ", constant";
if (getIsManaged())
p << ", managed";
if (getKind() == CUDADeviceVarKind::Surface)
p << ", surface_type = " << getSurfTexType();
p << ">";
}

Expand Down Expand Up @@ -650,6 +652,7 @@ Attribute CUDAVarRegistrationInfoAttr::parse(AsmParser &parser, Type odsType) {
bool isExtern = false;
bool isConstant = false;
bool isManaged = false;
int32_t surfTexType = 0;

while (parser.parseOptionalGreater().failed()) {
if (parser.parseComma())
Expand All @@ -665,14 +668,17 @@ Attribute CUDAVarRegistrationInfoAttr::parse(AsmParser &parser, Type odsType) {
isConstant = true;
else if (flag == "managed")
isManaged = true;
else {
else if (flag == "surface_type") {
if (parser.parseEqual() || parser.parseInteger(surfTexType))
return {};
} else {
parser.emitError(parser.getCurrentLocation(), "unknown flag: ") << flag;
return {};
}
}

return get(parser.getContext(), deviceSideName, *kind, isExtern, isConstant,
isManaged);
isManaged, surfTexType);
}

//===----------------------------------------------------------------------===//
Expand Down
Loading
Loading