Skip to content

Commit a9cb823

Browse files
authored
Merge branch 'main' into APX
2 parents f51c6bd + f623702 commit a9cb823

File tree

484 files changed

+14996
-3148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

484 files changed

+14996
-3148
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ Bug Fixes in This Version
134134
-------------------------
135135
- Fix a crash when marco name is empty in ``#pragma push_macro("")`` or
136136
``#pragma pop_macro("")``. (#GH149762).
137+
- `-Wunreachable-code`` now diagnoses tautological or contradictory
138+
comparisons such as ``x != 0 || x != 1.0`` and ``x == 0 && x == 1.0`` on
139+
targets that treat ``_Float16``/``__fp16`` as native scalar types. Previously
140+
the warning was silently lost because the operands differed only by an implicit
141+
cast chain. (#GH149967).
137142

138143
Bug Fixes to Compiler Builtins
139144
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
18181818
NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
18191819
} else {
18201820
NumNegativeBits =
1821-
std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
1821+
std::max(NumNegativeBits, InitVal.getSignificantBits());
18221822
}
18231823

18241824
MembersRepresentableByInt &= isRepresentableIntegerValue(InitVal, IntTy);

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,15 @@ TARGET_BUILTIN(__builtin_amdgcn_exp2_bf16, "yy", "nc", "bf16-trans-insts")
697697
TARGET_BUILTIN(__builtin_amdgcn_sin_bf16, "yy", "nc", "bf16-trans-insts")
698698
TARGET_BUILTIN(__builtin_amdgcn_cos_bf16, "yy", "nc", "bf16-trans-insts")
699699

700+
TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_pk_bf16_f32, "V2yffi", "nc", "bf16-cvt-insts")
700701
TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts")
701702
TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts")
702703
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_fp8, "V2hs", "nc", "gfx1250-insts")
703704
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_bf8, "V2hs", "nc", "gfx1250-insts")
705+
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f16, "sV2h", "nc", "gfx1250-insts")
706+
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f16, "sV2h", "nc", "gfx1250-insts")
707+
TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f16, "ihiUiIi", "nc", "gfx1250-insts")
708+
TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f16, "ihiUiIi", "nc", "gfx1250-insts")
704709
TARGET_BUILTIN(__builtin_amdgcn_sat_pk4_i4_i8, "UsUi", "nc", "gfx1250-insts")
705710
TARGET_BUILTIN(__builtin_amdgcn_sat_pk4_u4_u8, "UsUi", "nc", "gfx1250-insts")
706711

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,6 +5312,8 @@ def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Grou
53125312
def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>;
53135313
def mfp16 : Flag<["-"], "mfp16">, Group<m_wasm_Features_Group>;
53145314
def mno_fp16 : Flag<["-"], "mno-fp16">, Group<m_wasm_Features_Group>;
5315+
def mgc : Flag<["-"], "mgc">, Group<m_wasm_Features_Group>;
5316+
def mno_gc : Flag<["-"], "mno-gc">, Group<m_wasm_Features_Group>;
53155317
def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
53165318
def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
53175319
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,17 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
457457
assert(isPtrType(*FromT));
458458
assert(isPtrType(*ToT));
459459
if (FromT == ToT) {
460-
if (CE->getType()->isVoidPointerType())
460+
if (CE->getType()->isVoidPointerType() &&
461+
!SubExprTy->isFunctionPointerType()) {
461462
return this->delegate(SubExpr);
463+
}
462464

463465
if (!this->visit(SubExpr))
464466
return false;
465-
if (CE->getType()->isFunctionPointerType())
466-
return true;
467+
if (CE->getType()->isFunctionPointerType() ||
468+
SubExprTy->isFunctionPointerType()) {
469+
return this->emitFnPtrCast(CE);
470+
}
467471
if (FromT == PT_Ptr)
468472
return this->emitPtrPtrCast(SubExprTy->isVoidPointerType(), CE);
469473
return true;

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "clang/AST/Decl.h"
2222
#include "clang/AST/Expr.h"
2323
#include "clang/AST/StmtVisitor.h"
24-
#include "clang/Basic/TargetInfo.h"
2524

2625
namespace clang {
2726
class QualType;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "InterpStack.h"
2626
#include "InterpState.h"
2727
#include "MemberPointer.h"
28-
#include "Opcode.h"
2928
#include "PrimType.h"
3029
#include "Program.h"
3130
#include "State.h"
@@ -1131,8 +1130,9 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
11311130
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
11321131
<< LHS.toDiagnosticString(S.getASTContext());
11331132
return false;
1134-
} else if (RHS.isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
1135-
LHS.getOffset() == 0) {
1133+
}
1134+
if (RHS.isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
1135+
LHS.getOffset() == 0) {
11361136
const SourceInfo &Loc = S.Current->getSource(OpPC);
11371137
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
11381138
<< RHS.toDiagnosticString(S.getASTContext());
@@ -1150,8 +1150,9 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
11501150
const SourceInfo &Loc = S.Current->getSource(OpPC);
11511151
S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
11521152
return false;
1153-
} else if (const auto *CE = dyn_cast<CallExpr>(E);
1154-
CE && IsOpaqueConstantCall(CE)) {
1153+
}
1154+
if (const auto *CE = dyn_cast<CallExpr>(E);
1155+
CE && IsOpaqueConstantCall(CE)) {
11551156
const SourceInfo &Loc = S.Current->getSource(OpPC);
11561157
S.FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
11571158
<< P.toDiagnosticString(S.getASTContext());
@@ -2681,6 +2682,14 @@ static inline bool CastFixedPointIntegral(InterpState &S, CodePtr OpPC) {
26812682
return true;
26822683
}
26832684

2685+
static inline bool FnPtrCast(InterpState &S, CodePtr OpPC) {
2686+
const SourceInfo &E = S.Current->getSource(OpPC);
2687+
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2688+
<< diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
2689+
<< S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2690+
return true;
2691+
}
2692+
26842693
static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) {
26852694
const auto &Ptr = S.Stk.peek<Pointer>();
26862695

@@ -3266,7 +3275,8 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
32663275
S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
32673276
<< static_cast<unsigned>(Kind) << S.Current->getRange(OpPC);
32683277
return !Fatal;
3269-
} else if (Kind == CastKind::Volatile) {
3278+
}
3279+
if (Kind == CastKind::Volatile) {
32703280
if (!S.checkingPotentialConstantExpression()) {
32713281
const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC));
32723282
if (S.getLangOpts().CPlusPlus)
@@ -3277,7 +3287,8 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
32773287
}
32783288

32793289
return false;
3280-
} else if (Kind == CastKind::Dynamic) {
3290+
}
3291+
if (Kind == CastKind::Dynamic) {
32813292
assert(!S.getLangOpts().CPlusPlus20);
32823293
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
32833294
<< diag::ConstexprInvalidCastKind::Dynamic;

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ def PtrPtrCast : Opcode {
735735

736736
}
737737

738+
def FnPtrCast : Opcode;
739+
738740
def DecayPtr : Opcode {
739741
let Types = [PtrTypeClass, PtrTypeClass];
740742
let HasGroup = 1;

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5988,11 +5988,10 @@ bool clang::IsArmStreamingFunction(const FunctionDecl *FD,
59885988
if (FD->hasAttr<ArmLocallyStreamingAttr>())
59895989
return true;
59905990

5991-
if (const Type *Ty = FD->getType().getTypePtrOrNull())
5992-
if (const auto *FPT = Ty->getAs<FunctionProtoType>())
5993-
if (FPT->getAArch64SMEAttributes() &
5994-
FunctionType::SME_PStateSMEnabledMask)
5995-
return true;
5991+
assert(!FD->getType().isNull() && "Expected a valid FunctionDecl");
5992+
if (const auto *FPT = FD->getType()->getAs<FunctionProtoType>())
5993+
if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
5994+
return true;
59965995

59975996
return false;
59985997
}

clang/lib/AST/Expr.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,8 +4233,15 @@ bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) {
42334233
// template parameters.
42344234
const auto *DRE1 = cast<DeclRefExpr>(E1);
42354235
const auto *DRE2 = cast<DeclRefExpr>(E2);
4236-
return DRE1->isPRValue() && DRE2->isPRValue() &&
4237-
DRE1->getDecl() == DRE2->getDecl();
4236+
4237+
if (DRE1->getDecl() != DRE2->getDecl())
4238+
return false;
4239+
4240+
if ((DRE1->isPRValue() && DRE2->isPRValue()) ||
4241+
(DRE1->isLValue() && DRE2->isLValue()))
4242+
return true;
4243+
4244+
return false;
42384245
}
42394246
case ImplicitCastExprClass: {
42404247
// Peel off implicit casts.
@@ -4244,7 +4251,8 @@ bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) {
42444251
if (!ICE1 || !ICE2)
42454252
return false;
42464253
if (ICE1->getCastKind() != ICE2->getCastKind())
4247-
return false;
4254+
return isSameComparisonOperand(ICE1->IgnoreParenImpCasts(),
4255+
ICE2->IgnoreParenImpCasts());
42484256
E1 = ICE1->getSubExpr()->IgnoreParens();
42494257
E2 = ICE2->getSubExpr()->IgnoreParens();
42504258
// The final cast must be one of these types.

0 commit comments

Comments
 (0)