Skip to content

Commit 6e052f4

Browse files
Merge branch 'llvm:main' into copy-inout-dev
2 parents fb3a93c + 596640a commit 6e052f4

File tree

169 files changed

+5384
-992
lines changed

Some content is hidden

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

169 files changed

+5384
-992
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/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/Interp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,14 @@ static inline bool CastFixedPointIntegral(InterpState &S, CodePtr OpPC) {
26822682
return true;
26832683
}
26842684

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+
26852693
static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) {
26862694
const auto &Ptr = S.Stk.peek<Pointer>();
26872695

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/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.

clang/lib/AST/ExprConstant.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9741,10 +9741,19 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
97419741
case CK_AddressSpaceConversion:
97429742
if (!Visit(SubExpr))
97439743
return false;
9744-
// Bitcasts to cv void* are static_casts, not reinterpret_casts, so are
9745-
// permitted in constant expressions in C++11. Bitcasts from cv void* are
9746-
// also static_casts, but we disallow them as a resolution to DR1312.
9747-
if (!E->getType()->isVoidPointerType()) {
9744+
if (E->getType()->isFunctionPointerType() ||
9745+
SubExpr->getType()->isFunctionPointerType()) {
9746+
// Casting between two function pointer types, or between a function
9747+
// pointer and an object pointer, is always a reinterpret_cast.
9748+
CCEDiag(E, diag::note_constexpr_invalid_cast)
9749+
<< diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
9750+
<< Info.Ctx.getLangOpts().CPlusPlus;
9751+
Result.Designator.setInvalid();
9752+
} else if (!E->getType()->isVoidPointerType()) {
9753+
// Bitcasts to cv void* are static_casts, not reinterpret_casts, so are
9754+
// permitted in constant expressions in C++11. Bitcasts from cv void* are
9755+
// also static_casts, but we disallow them as a resolution to DR1312.
9756+
//
97489757
// In some circumstances, we permit casting from void* to cv1 T*, when the
97499758
// actual pointee object is actually a cv2 T.
97509759
bool HasValidResult = !Result.InvalidBase && !Result.Designator.Invalid &&

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
5959
.Case("exception-handling", HasExceptionHandling)
6060
.Case("extended-const", HasExtendedConst)
6161
.Case("fp16", HasFP16)
62+
.Case("gc", HasGC)
6263
.Case("multimemory", HasMultiMemory)
6364
.Case("multivalue", HasMultivalue)
6465
.Case("mutable-globals", HasMutableGlobals)
6566
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
6667
.Case("reference-types", HasReferenceTypes)
67-
.Case("gc", HasGC)
6868
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
6969
.Case("sign-ext", HasSignExt)
7070
.Case("simd128", SIMDLevel >= SIMD128)
@@ -99,6 +99,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
9999
Builder.defineMacro("__wasm_multimemory__");
100100
if (HasFP16)
101101
Builder.defineMacro("__wasm_fp16__");
102+
if (HasGC)
103+
Builder.defineMacro("__wasm_gc__");
102104
if (HasMultivalue)
103105
Builder.defineMacro("__wasm_multivalue__");
104106
if (HasMutableGlobals)
@@ -107,8 +109,6 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
107109
Builder.defineMacro("__wasm_nontrapping_fptoint__");
108110
if (HasReferenceTypes)
109111
Builder.defineMacro("__wasm_reference_types__");
110-
if (HasGC)
111-
Builder.defineMacro("__wasm_gc__");
112112
if (SIMDLevel >= RelaxedSIMD)
113113
Builder.defineMacro("__wasm_relaxed_simd__");
114114
if (HasSignExt)
@@ -194,6 +194,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
194194
Features["exception-handling"] = true;
195195
Features["extended-const"] = true;
196196
Features["fp16"] = true;
197+
Features["gc"] = true;
197198
Features["multimemory"] = true;
198199
Features["tail-call"] = true;
199200
Features["wide-arithmetic"] = true;
@@ -270,6 +271,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
270271
HasFP16 = false;
271272
continue;
272273
}
274+
if (Feature == "+gc") {
275+
HasGC = true;
276+
continue;
277+
}
278+
if (Feature == "-gc") {
279+
HasGC = false;
280+
continue;
281+
}
273282
if (Feature == "+multimemory") {
274283
HasMultiMemory = true;
275284
continue;
@@ -310,14 +319,6 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
310319
HasReferenceTypes = false;
311320
continue;
312321
}
313-
if (Feature == "+gc") {
314-
HasGC = true;
315-
continue;
316-
}
317-
if (Feature == "-gc") {
318-
HasGC = false;
319-
continue;
320-
}
321322
if (Feature == "+relaxed-simd") {
322323
SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
323324
continue;

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6464
bool HasExceptionHandling = false;
6565
bool HasExtendedConst = false;
6666
bool HasFP16 = false;
67+
bool HasGC = false;
6768
bool HasMultiMemory = false;
6869
bool HasMultivalue = false;
6970
bool HasMutableGlobals = false;
7071
bool HasNontrappingFPToInt = false;
7172
bool HasReferenceTypes = false;
72-
bool HasGC = false;
7373
bool HasSignExt = false;
7474
bool HasTailCall = false;
7575
bool HasWideArithmetic = false;

0 commit comments

Comments
 (0)