Skip to content

Commit e616b31

Browse files
authored
Merge branch 'main' into hlsl-waveactiveanytrue
2 parents 4dd242a + 2f55de4 commit e616b31

File tree

69 files changed

+1918
-1144
lines changed

Some content is hidden

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

69 files changed

+1918
-1144
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ jobs:
202202
matrix:
203203
include:
204204
- config: generic-cxx03
205-
os: macos-latest
205+
os: macos-15
206206
- config: generic-cxx23
207-
os: macos-latest
207+
os: macos-15
208208
- config: generic-modules
209-
os: macos-latest
209+
os: macos-15
210210
- config: apple-configuration
211-
os: macos-latest
211+
os: macos-15
212212
- config: apple-system
213213
os: macos-13
214214
- config: apple-system-hardened

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {
6060
// Filesystem
6161

6262
INTERCEPTOR(int, open, const char *path, int oflag, ...) {
63-
// TODO Establish whether we should intercept here if the flag contains
64-
// O_NONBLOCK
63+
// We do not early exit if O_NONBLOCK is set.
64+
// O_NONBLOCK **does not prevent the syscall** it simply sets the FD to be in
65+
// nonblocking mode, which is a different concept than our
66+
// [[clang::nonblocking]], and is not rt-safe. This behavior was confirmed
67+
// using Instruments on Darwin with a simple test program
6568
__rtsan_notify_intercepted_call("open");
6669

6770
if (OpenReadsVaArgs(oflag)) {
@@ -77,8 +80,7 @@ INTERCEPTOR(int, open, const char *path, int oflag, ...) {
7780

7881
#if SANITIZER_INTERCEPT_OPEN64
7982
INTERCEPTOR(int, open64, const char *path, int oflag, ...) {
80-
// TODO Establish whether we should intercept here if the flag contains
81-
// O_NONBLOCK
83+
// See comment above about O_NONBLOCK
8284
__rtsan_notify_intercepted_call("open64");
8385

8486
if (OpenReadsVaArgs(oflag)) {
@@ -97,8 +99,7 @@ INTERCEPTOR(int, open64, const char *path, int oflag, ...) {
9799
#endif // SANITIZER_INTERCEPT_OPEN64
98100

99101
INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {
100-
// TODO Establish whether we should intercept here if the flag contains
101-
// O_NONBLOCK
102+
// See comment above about O_NONBLOCK
102103
__rtsan_notify_intercepted_call("openat");
103104

104105
if (OpenReadsVaArgs(oflag)) {
@@ -114,8 +115,7 @@ INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {
114115

115116
#if SANITIZER_INTERCEPT_OPENAT64
116117
INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {
117-
// TODO Establish whether we should intercept here if the flag contains
118-
// O_NONBLOCK
118+
// See comment above about O_NONBLOCK
119119
__rtsan_notify_intercepted_call("openat64");
120120

121121
if (OpenReadsVaArgs(oflag)) {
@@ -134,17 +134,15 @@ INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {
134134
#endif // SANITIZER_INTERCEPT_OPENAT64
135135

136136
INTERCEPTOR(int, creat, const char *path, mode_t mode) {
137-
// TODO Establish whether we should intercept here if the flag contains
138-
// O_NONBLOCK
137+
// See comment above about O_NONBLOCK
139138
__rtsan_notify_intercepted_call("creat");
140139
const int result = REAL(creat)(path, mode);
141140
return result;
142141
}
143142

144143
#if SANITIZER_INTERCEPT_CREAT64
145144
INTERCEPTOR(int, creat64, const char *path, mode_t mode) {
146-
// TODO Establish whether we should intercept here if the flag contains
147-
// O_NONBLOCK
145+
// See comment above about O_NONBLOCK
148146
__rtsan_notify_intercepted_call("creat64");
149147
const int result = REAL(creat64)(path, mode);
150148
return result;

flang/include/flang/Common/Fortran-features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
5353
NonBindCInteroperability, CudaManaged, CudaUnified,
5454
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
5555
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
56-
SavedLocalInSpecExpr, PrintNamelist)
56+
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank)
5757

5858
// Portability and suspicious usage warnings
5959
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,

flang/include/flang/Evaluate/tools.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,7 @@ extern template semantics::UnorderedSymbolSet CollectCudaSymbols(
11031103
bool HasVectorSubscript(const Expr<SomeType> &);
11041104

11051105
// Utilities for attaching the location of the declaration of a symbol
1106-
// of interest to a message, if both pointers are non-null. Handles
1107-
// the case of USE association gracefully.
1106+
// of interest to a message. Handles the case of USE association gracefully.
11081107
parser::Message *AttachDeclaration(parser::Message &, const Symbol &);
11091108
parser::Message *AttachDeclaration(parser::Message *, const Symbol &);
11101109
template <typename MESSAGES, typename... A>

flang/lib/Common/Fortran-features.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ LanguageFeatureControl::LanguageFeatureControl() {
3030
disable_.set(LanguageFeature::LogicalAbbreviations);
3131
disable_.set(LanguageFeature::XOROperator);
3232
disable_.set(LanguageFeature::OldStyleParameter);
33+
// Possibly an accidental "feature" of nvfortran.
34+
disable_.set(LanguageFeature::AssumedRankPassedToNonAssumedRank);
3335
// These warnings are enabled by default, but only because they used
3436
// to be unconditional. TODO: prune this list
3537
warnLanguage_.set(LanguageFeature::ExponentMatchingKindParam);

flang/lib/Evaluate/check-expression.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,58 @@ class IsContiguousHelper
908908
Result operator()(const ComplexPart &x) const {
909909
return x.complex().Rank() == 0;
910910
}
911-
Result operator()(const Substring &) const { return std::nullopt; }
911+
Result operator()(const Substring &x) const {
912+
if (x.Rank() == 0) {
913+
return true; // scalar substring always contiguous
914+
}
915+
// Substrings with rank must have DataRefs as their parents
916+
const DataRef &parentDataRef{DEREF(x.GetParentIf<DataRef>())};
917+
std::optional<std::int64_t> len;
918+
if (auto lenExpr{parentDataRef.LEN()}) {
919+
len = ToInt64(Fold(context_, std::move(*lenExpr)));
920+
if (len) {
921+
if (*len <= 0) {
922+
return true; // empty substrings
923+
} else if (*len == 1) {
924+
// Substrings can't be incomplete; is base array contiguous?
925+
return (*this)(parentDataRef);
926+
}
927+
}
928+
}
929+
std::optional<std::int64_t> upper;
930+
bool upperIsLen{false};
931+
if (auto upperExpr{x.upper()}) {
932+
upper = ToInt64(Fold(context_, common::Clone(*upperExpr)));
933+
if (upper) {
934+
if (*upper < 1) {
935+
return true; // substring(n:0) empty
936+
}
937+
upperIsLen = len && *upper >= *len;
938+
} else if (const auto *inquiry{
939+
UnwrapConvertedExpr<DescriptorInquiry>(*upperExpr)};
940+
inquiry && inquiry->field() == DescriptorInquiry::Field::Len) {
941+
upperIsLen =
942+
&parentDataRef.GetLastSymbol() == &inquiry->base().GetLastSymbol();
943+
}
944+
} else {
945+
upperIsLen = true; // substring(n:)
946+
}
947+
if (auto lower{ToInt64(Fold(context_, x.lower()))}) {
948+
if (*lower == 1 && upperIsLen) {
949+
// known complete substring; is base contiguous?
950+
return (*this)(parentDataRef);
951+
} else if (upper) {
952+
if (*upper < *lower) {
953+
return true; // empty substring(3:2)
954+
} else if (*lower > 1) {
955+
return false; // known incomplete substring
956+
} else if (len && *upper < *len) {
957+
return false; // known incomplete substring
958+
}
959+
}
960+
}
961+
return std::nullopt; // contiguity not known
962+
}
912963

913964
Result operator()(const ProcedureRef &x) const {
914965
if (auto chars{characteristics::Procedure::Characterize(

flang/lib/Evaluate/fold-integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
873873
} else {
874874
DIE("first argument must be CHARACTER");
875875
}
876-
} else if (name == "int") {
876+
} else if (name == "int" || name == "int2" || name == "int8") {
877877
if (auto *expr{UnwrapExpr<Expr<SomeType>>(args[0])}) {
878878
return common::visit(
879879
[&](auto &&x) -> Expr<T> {

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ static constexpr TypePattern SameCharNoLen{CharType, KindCode::sameKind};
168168
static constexpr TypePattern SameLogical{LogicalType, KindCode::same};
169169
static constexpr TypePattern SameRelatable{RelatableType, KindCode::same};
170170
static constexpr TypePattern SameIntrinsic{IntrinsicType, KindCode::same};
171-
static constexpr TypePattern SameDerivedType{
172-
CategorySet{TypeCategory::Derived}, KindCode::same};
173171
static constexpr TypePattern SameType{AnyType, KindCode::same};
174172

175173
// Match some kind of some INTEGER or REAL type(s); when argument types
@@ -438,6 +436,12 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
438436
{"shift", AnyInt}},
439437
SameInt},
440438
{"dshiftr", {{"i", BOZ}, {"j", SameInt}, {"shift", AnyInt}}, SameInt},
439+
{"eoshift",
440+
{{"array", SameType, Rank::array},
441+
{"shift", AnyInt, Rank::dimRemovedOrScalar},
442+
// BOUNDARY= is not optional for non-intrinsic types
443+
{"boundary", SameType, Rank::dimRemovedOrScalar}, OptionalDIM},
444+
SameType, Rank::conformable, IntrinsicClass::transformationalFunction},
441445
{"eoshift",
442446
{{"array", SameIntrinsic, Rank::array},
443447
{"shift", AnyInt, Rank::dimRemovedOrScalar},
@@ -446,14 +450,6 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
446450
OptionalDIM},
447451
SameIntrinsic, Rank::conformable,
448452
IntrinsicClass::transformationalFunction},
449-
{"eoshift",
450-
{{"array", SameDerivedType, Rank::array},
451-
{"shift", AnyInt, Rank::dimRemovedOrScalar},
452-
// BOUNDARY= is not optional for derived types
453-
{"boundary", SameDerivedType, Rank::dimRemovedOrScalar},
454-
OptionalDIM},
455-
SameDerivedType, Rank::conformable,
456-
IntrinsicClass::transformationalFunction},
457453
{"epsilon",
458454
{{"x", SameReal, Rank::anyOrAssumedRank, Optionality::required,
459455
common::Intent::In, {ArgFlag::canBeMoldNull}}},
@@ -572,6 +568,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
572568
DefaultingKIND},
573569
KINDInt},
574570
{"int", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDInt},
571+
{"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
572+
TypePattern{IntType, KindCode::exactKind, 2}},
573+
{"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
574+
TypePattern{IntType, KindCode::exactKind, 8}},
575575
{"int_ptr_kind", {}, DefaultInt, Rank::scalar},
576576
{"ior", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
577577
OperandInt},
@@ -1176,12 +1176,6 @@ static const SpecificIntrinsicInterface specificIntrinsicFunction[]{
11761176
// procedure pointer target.
11771177
{{"index", {{"string", DefaultChar}, {"substring", DefaultChar}},
11781178
DefaultInt}},
1179-
{{"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
1180-
TypePattern{IntType, KindCode::exactKind, 2}},
1181-
"int"},
1182-
{{"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
1183-
TypePattern{IntType, KindCode::exactKind, 8}},
1184-
"int"},
11851179
{{"isign", {{"a", DefaultInt}, {"b", DefaultInt}}, DefaultInt}, "sign"},
11861180
{{"jiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 4}}},
11871181
TypePattern{IntType, KindCode::exactKind, 4}},
@@ -1939,12 +1933,16 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
19391933
dimArg = j;
19401934
argOk = true;
19411935
break;
1942-
case KindCode::same:
1936+
case KindCode::same: {
19431937
if (!sameArg) {
19441938
sameArg = arg;
19451939
}
1946-
argOk = type->IsTkLenCompatibleWith(sameArg->GetType().value());
1947-
break;
1940+
// Check both ways so that a CLASS(*) actuals to
1941+
// MOVE_ALLOC and EOSHIFT both work.
1942+
auto sameType{sameArg->GetType().value()};
1943+
argOk = sameType.IsTkLenCompatibleWith(*type) ||
1944+
type->IsTkLenCompatibleWith(sameType);
1945+
} break;
19481946
case KindCode::sameKind:
19491947
if (!sameArg) {
19501948
sameArg = arg;
@@ -2849,15 +2847,16 @@ IntrinsicProcTable::Implementation::HandleC_F_Pointer(
28492847
"FPTR= argument to C_F_POINTER() may not have a deferred type parameter"_err_en_US);
28502848
} else if (type->category() == TypeCategory::Derived) {
28512849
if (context.languageFeatures().ShouldWarn(
2852-
common::UsageWarning::Interoperability)) {
2853-
if (type->IsUnlimitedPolymorphic()) {
2854-
context.messages().Say(common::UsageWarning::Interoperability, at,
2855-
"FPTR= argument to C_F_POINTER() should not be unlimited polymorphic"_warn_en_US);
2856-
} else if (!type->GetDerivedTypeSpec().typeSymbol().attrs().test(
2857-
semantics::Attr::BIND_C)) {
2858-
context.messages().Say(common::UsageWarning::Interoperability, at,
2859-
"FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C)"_warn_en_US);
2860-
}
2850+
common::UsageWarning::Interoperability) &&
2851+
type->IsUnlimitedPolymorphic()) {
2852+
context.messages().Say(common::UsageWarning::Interoperability, at,
2853+
"FPTR= argument to C_F_POINTER() should not be unlimited polymorphic"_warn_en_US);
2854+
} else if (!type->GetDerivedTypeSpec().typeSymbol().attrs().test(
2855+
semantics::Attr::BIND_C) &&
2856+
context.languageFeatures().ShouldWarn(
2857+
common::UsageWarning::Portability)) {
2858+
context.messages().Say(common::UsageWarning::Portability, at,
2859+
"FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C)"_port_en_US);
28612860
}
28622861
} else if (!IsInteroperableIntrinsicType(
28632862
*type, &context.languageFeatures())

flang/lib/Semantics/check-call.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ static void CheckCharacterActual(evaluate::Expr<evaluate::SomeType> &actual,
135135
dummy.type.type().kind() == actualType.type().kind() &&
136136
!dummy.attrs.test(
137137
characteristics::DummyDataObject::Attr::DeducedFromActual)) {
138+
bool actualIsAssumedRank{evaluate::IsAssumedRank(actual)};
139+
if (actualIsAssumedRank &&
140+
!dummy.type.attrs().test(
141+
characteristics::TypeAndShape::Attr::AssumedRank)) {
142+
if (!context.languageFeatures().IsEnabled(
143+
common::LanguageFeature::AssumedRankPassedToNonAssumedRank)) {
144+
messages.Say(
145+
"Assumed-rank character array may not be associated with a dummy argument that is not assumed-rank"_err_en_US);
146+
} else {
147+
context.Warn(common::LanguageFeature::AssumedRankPassedToNonAssumedRank,
148+
messages.at(),
149+
"Assumed-rank character array should not be associated with a dummy argument that is not assumed-rank"_port_en_US);
150+
}
151+
}
138152
if (dummy.type.LEN() && actualType.LEN()) {
139153
evaluate::FoldingContext &foldingContext{context.foldingContext()};
140154
auto dummyLength{
@@ -148,7 +162,7 @@ static void CheckCharacterActual(evaluate::Expr<evaluate::SomeType> &actual,
148162
if (auto dummySize{evaluate::ToInt64(evaluate::Fold(
149163
foldingContext, evaluate::GetSize(dummy.type.shape())))}) {
150164
auto dummyChars{*dummySize * *dummyLength};
151-
if (actualType.Rank() == 0) {
165+
if (actualType.Rank() == 0 && !actualIsAssumedRank) {
152166
evaluate::DesignatorFolder folder{
153167
context.foldingContext(), /*getLastComponent=*/true};
154168
if (auto actualOffset{folder.FoldDesignator(actual)}) {
@@ -602,7 +616,18 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
602616
characteristics::DummyDataObject::Attr::DeducedFromActual)) {
603617
if (auto dummySize{evaluate::ToInt64(evaluate::Fold(
604618
foldingContext, evaluate::GetSize(dummy.type.shape())))}) {
605-
if (actualRank == 0 && !actualIsAssumedRank) {
619+
if (actualIsAssumedRank) {
620+
if (!context.languageFeatures().IsEnabled(
621+
common::LanguageFeature::AssumedRankPassedToNonAssumedRank)) {
622+
messages.Say(
623+
"Assumed-rank array may not be associated with a dummy argument that is not assumed-rank"_err_en_US);
624+
} else {
625+
context.Warn(
626+
common::LanguageFeature::AssumedRankPassedToNonAssumedRank,
627+
messages.at(),
628+
"Assumed-rank array should not be associated with a dummy argument that is not assumed-rank"_port_en_US);
629+
}
630+
} else if (actualRank == 0) {
606631
if (evaluate::IsArrayElement(actual)) {
607632
// Actual argument is a scalar array element
608633
evaluate::DesignatorFolder folder{
@@ -643,7 +668,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
643668
}
644669
}
645670
}
646-
} else { // actualRank > 0 || actualIsAssumedRank
671+
} else {
647672
if (auto actualSize{evaluate::ToInt64(evaluate::Fold(
648673
foldingContext, evaluate::GetSize(actualType.shape())))};
649674
actualSize && *actualSize < *dummySize) {

flang/lib/Semantics/check-declarations.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ class CheckHelper {
147147
void CheckProcedureAssemblyName(const Symbol &symbol);
148148
void CheckExplicitSave(const Symbol &);
149149
parser::Messages WhyNotInteroperableDerivedType(const Symbol &);
150-
parser::Messages WhyNotInteroperableObject(const Symbol &);
150+
parser::Messages WhyNotInteroperableObject(
151+
const Symbol &, bool allowNonInteroperableType = false);
151152
parser::Messages WhyNotInteroperableFunctionResult(const Symbol &);
152153
parser::Messages WhyNotInteroperableProcedure(const Symbol &, bool isError);
153154
void CheckBindC(const Symbol &);
@@ -3001,7 +3002,8 @@ parser::Messages CheckHelper::WhyNotInteroperableDerivedType(
30013002
return msgs;
30023003
}
30033004

3004-
parser::Messages CheckHelper::WhyNotInteroperableObject(const Symbol &symbol) {
3005+
parser::Messages CheckHelper::WhyNotInteroperableObject(
3006+
const Symbol &symbol, bool allowNonInteroperableType) {
30053007
parser::Messages msgs;
30063008
if (examinedByWhyNotInteroperable_.find(symbol) !=
30073009
examinedByWhyNotInteroperable_.end()) {
@@ -3037,8 +3039,13 @@ parser::Messages CheckHelper::WhyNotInteroperableObject(const Symbol &symbol) {
30373039
if (const auto *type{symbol.GetType()}) {
30383040
const auto *derived{type->AsDerived()};
30393041
if (derived && !derived->typeSymbol().attrs().test(Attr::BIND_C)) {
3040-
if (!context_.IsEnabled(
3041-
common::LanguageFeature::NonBindCInteroperability)) {
3042+
if (allowNonInteroperableType) { // portability warning only
3043+
evaluate::AttachDeclaration(
3044+
context_.Warn(common::UsageWarning::Portability, symbol.name(),
3045+
"The derived type of this interoperable object should be BIND(C)"_port_en_US),
3046+
derived->typeSymbol());
3047+
} else if (!context_.IsEnabled(
3048+
common::LanguageFeature::NonBindCInteroperability)) {
30423049
msgs.Say(symbol.name(),
30433050
"The derived type of an interoperable object must be BIND(C)"_err_en_US)
30443051
.Attach(derived->typeSymbol().name(), "Non-BIND(C) type"_en_US);
@@ -3178,7 +3185,13 @@ parser::Messages CheckHelper::WhyNotInteroperableProcedure(
31783185
"A dummy procedure of an interoperable procedure should be BIND(C)"_warn_en_US);
31793186
}
31803187
} else if (dummy->has<ObjectEntityDetails>()) {
3181-
dummyMsgs = WhyNotInteroperableObject(*dummy);
3188+
// Emit only optional portability warnings for non-interoperable
3189+
// types when the dummy argument is not VALUE and will be implemented
3190+
// on the C side by either a cdesc_t * or a void *. F'2023 18.3.7 (5)
3191+
bool allowNonInteroperableType{!dummy->attrs().test(Attr::VALUE) &&
3192+
(IsDescriptor(*dummy) || IsAssumedType(*dummy))};
3193+
dummyMsgs =
3194+
WhyNotInteroperableObject(*dummy, allowNonInteroperableType);
31823195
} else {
31833196
CheckBindC(*dummy);
31843197
}

0 commit comments

Comments
 (0)