Skip to content

Commit 6d88f32

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (26 commits)
2 parents 62626ca + 1c93781 commit 6d88f32

File tree

89 files changed

+2901
-412
lines changed

Some content is hidden

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

89 files changed

+2901
-412
lines changed

clang/include/clang/Basic/RISCVVTypes.def

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
452452

453453
RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 4, 64, 2)
454454

455+
//===- BFloat16 tuple types -------------------------------------------------===//
456+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, RvvBFloat16mf4x2Ty,
457+
1, 16, 2)
458+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, RvvBFloat16mf4x3Ty,
459+
1, 16, 3)
460+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, RvvBFloat16mf4x4Ty,
461+
1, 16, 4)
462+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, RvvBFloat16mf4x5Ty,
463+
1, 16, 5)
464+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, RvvBFloat16mf4x6Ty,
465+
1, 16, 6)
466+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, RvvBFloat16mf4x7Ty,
467+
1, 16, 7)
468+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, RvvBFloat16mf4x8Ty,
469+
1, 16, 8)
470+
471+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, RvvBFloat16mf2x2Ty,
472+
2, 16, 2)
473+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, RvvBFloat16mf2x3Ty,
474+
2, 16, 3)
475+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, RvvBFloat16mf2x4Ty,
476+
2, 16, 4)
477+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, RvvBFloat16mf2x5Ty,
478+
2, 16, 5)
479+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, RvvBFloat16mf2x6Ty,
480+
2, 16, 6)
481+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, RvvBFloat16mf2x7Ty,
482+
2, 16, 7)
483+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, RvvBFloat16mf2x8Ty,
484+
2, 16, 8)
485+
486+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, RvvBFloat16m1x2Ty,
487+
4, 16, 2)
488+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, RvvBFloat16m1x3Ty,
489+
4, 16, 3)
490+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, RvvBFloat16m1x4Ty,
491+
4, 16, 4)
492+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, RvvBFloat16m1x5Ty,
493+
4, 16, 5)
494+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, RvvBFloat16m1x6Ty,
495+
4, 16, 6)
496+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, RvvBFloat16m1x7Ty,
497+
4, 16, 7)
498+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, RvvBFloat16m1x8Ty,
499+
4, 16, 8)
500+
501+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, RvvBFloat16m2x2Ty,
502+
8, 16, 2)
503+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, RvvBFloat16m2x3Ty,
504+
8, 16, 3)
505+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, RvvBFloat16m2x4Ty,
506+
8, 16, 4)
507+
508+
RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, RvvBFloat16m4x2Ty,
509+
16, 16, 2)
510+
455511
#undef RVV_VECTOR_TYPE_BFLOAT
456512
#undef RVV_VECTOR_TYPE_FLOAT
457513
#undef RVV_VECTOR_TYPE_INT

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ enum PredefinedTypeIDs {
11061106
///
11071107
/// Type IDs for non-predefined types will start at
11081108
/// NUM_PREDEF_TYPE_IDs.
1109-
const unsigned NUM_PREDEF_TYPE_IDS = 500;
1109+
const unsigned NUM_PREDEF_TYPE_IDS = 502;
11101110

11111111
// Ensure we do not overrun the predefined types we reserved
11121112
// in the enum PredefinedTypeIDs above.

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ enum class TypeModifier : uint8_t {
9797
UnsignedInteger = 1 << 3,
9898
SignedInteger = 1 << 4,
9999
Float = 1 << 5,
100+
BFloat = 1 << 6,
100101
// LMUL1 should be kind of VectorTypeModifier, but that might come with
101102
// Widening2XVector for widening reduction.
102103
// However that might require VectorTypeModifier become bitmask rather than
103104
// simple enum, so we decide keek LMUL1 in TypeModifier for code size
104105
// optimization of clang binary size.
105-
LMUL1 = 1 << 6,
106-
MaxOffset = 6,
106+
LMUL1 = 1 << 7,
107+
MaxOffset = 7,
107108
LLVM_MARK_AS_BITMASK_ENUM(LMUL1),
108109
};
109110

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
346346
}
347347
}
348348

349+
if (Next->is(tok::kw_auto))
350+
TypeToken = Next;
351+
349352
// Place the Qualifier at the end of the list of qualifiers.
350353
while (isQualifier(TypeToken->getNextNonComment())) {
351354
// The case `volatile Foo::iter const` -> `Foo::iter const volatile`
@@ -446,6 +449,9 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
446449
return false;
447450
}
448451

452+
if (Tok->endsSequence(tok::kw_auto, tok::identifier))
453+
return false;
454+
449455
return true;
450456
};
451457

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,10 +2018,6 @@ class AnnotatingParser {
20182018
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
20192019
Contexts.back().FirstStartOfName = &Current;
20202020
Current.setType(TT_StartOfName);
2021-
if (auto *PrevNonComment = Current.getPreviousNonComment();
2022-
PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
2023-
PrevNonComment->setType(TT_Unknown);
2024-
}
20252021
} else if (Current.is(tok::semi)) {
20262022
// Reset FirstStartOfName after finding a semicolon so that a for loop
20272023
// with multiple increment statements is not confused with a for loop
@@ -2210,7 +2206,8 @@ class AnnotatingParser {
22102206
return false;
22112207

22122208
if (const auto *NextNonComment = Tok.getNextNonComment();
2213-
!NextNonComment || NextNonComment->isPointerOrReference()) {
2209+
!NextNonComment || NextNonComment->isPointerOrReference() ||
2210+
NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
22142211
return false;
22152212
}
22162213

clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ SVal CStringChecker::getCStringLengthForRegion(CheckerContext &C,
881881
const llvm::APSInt *maxLengthInt = BVF.evalAPSInt(BO_Div, maxValInt,
882882
fourInt);
883883
NonLoc maxLength = svalBuilder.makeIntVal(*maxLengthInt);
884-
SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn,
885-
maxLength, sizeTy);
884+
SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn, maxLength,
885+
svalBuilder.getConditionType());
886886
state = state->assume(evalLength.castAs<DefinedOrUnknownSVal>(), true);
887887
}
888888
state = state->set<CStringLength>(MR, strLength);

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,14 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
245245
{{{"fclose"}, 1},
246246
{&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
247247
{{{"fread"}, 4},
248-
{std::bind(&StreamChecker::preFreadFwrite, _1, _2, _3, _4, true),
248+
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
249249
std::bind(&StreamChecker::evalFreadFwrite, _1, _2, _3, _4, true), 3}},
250250
{{{"fwrite"}, 4},
251-
{std::bind(&StreamChecker::preFreadFwrite, _1, _2, _3, _4, false),
251+
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
252252
std::bind(&StreamChecker::evalFreadFwrite, _1, _2, _3, _4, false), 3}},
253+
{{{"fputc"}, 2},
254+
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
255+
&StreamChecker::evalFputc, 1}},
253256
{{{"fseek"}, 3},
254257
{&StreamChecker::preFseek, &StreamChecker::evalFseek, 0}},
255258
{{{"ftell"}, 1},
@@ -305,12 +308,15 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
305308
void evalFclose(const FnDescription *Desc, const CallEvent &Call,
306309
CheckerContext &C) const;
307310

308-
void preFreadFwrite(const FnDescription *Desc, const CallEvent &Call,
309-
CheckerContext &C, bool IsFread) const;
311+
void preReadWrite(const FnDescription *Desc, const CallEvent &Call,
312+
CheckerContext &C, bool IsRead) const;
310313

311314
void evalFreadFwrite(const FnDescription *Desc, const CallEvent &Call,
312315
CheckerContext &C, bool IsFread) const;
313316

317+
void evalFputc(const FnDescription *Desc, const CallEvent &Call,
318+
CheckerContext &C) const;
319+
314320
void preFseek(const FnDescription *Desc, const CallEvent &Call,
315321
CheckerContext &C) const;
316322
void evalFseek(const FnDescription *Desc, const CallEvent &Call,
@@ -634,9 +640,9 @@ void StreamChecker::evalFclose(const FnDescription *Desc, const CallEvent &Call,
634640
C.addTransition(StateFailure);
635641
}
636642

637-
void StreamChecker::preFreadFwrite(const FnDescription *Desc,
638-
const CallEvent &Call, CheckerContext &C,
639-
bool IsFread) const {
643+
void StreamChecker::preReadWrite(const FnDescription *Desc,
644+
const CallEvent &Call, CheckerContext &C,
645+
bool IsRead) const {
640646
ProgramStateRef State = C.getState();
641647
SVal StreamVal = getStreamArg(Desc, Call);
642648
State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
@@ -650,7 +656,7 @@ void StreamChecker::preFreadFwrite(const FnDescription *Desc,
650656
if (!State)
651657
return;
652658

653-
if (!IsFread) {
659+
if (!IsRead) {
654660
C.addTransition(State);
655661
return;
656662
}
@@ -719,9 +725,9 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
719725
NonLoc RetVal = makeRetVal(C, CE).castAs<NonLoc>();
720726
ProgramStateRef StateFailed =
721727
State->BindExpr(CE, C.getLocationContext(), RetVal);
728+
SValBuilder &SVB = C.getSValBuilder();
722729
auto Cond =
723-
C.getSValBuilder()
724-
.evalBinOpNN(State, BO_LT, RetVal, *NMembVal, C.getASTContext().IntTy)
730+
SVB.evalBinOpNN(State, BO_LT, RetVal, *NMembVal, SVB.getConditionType())
725731
.getAs<DefinedOrUnknownSVal>();
726732
if (!Cond)
727733
return;
@@ -745,6 +751,45 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
745751
C.addTransition(StateFailed);
746752
}
747753

754+
void StreamChecker::evalFputc(const FnDescription *Desc, const CallEvent &Call,
755+
CheckerContext &C) const {
756+
ProgramStateRef State = C.getState();
757+
SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
758+
if (!StreamSym)
759+
return;
760+
761+
const CallExpr *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
762+
if (!CE)
763+
return;
764+
765+
const StreamState *OldSS = State->get<StreamMap>(StreamSym);
766+
if (!OldSS)
767+
return;
768+
769+
assertStreamStateOpened(OldSS);
770+
771+
// `fputc` returns the written character on success, otherwise returns EOF.
772+
773+
// Generate a transition for the success state.
774+
std::optional<NonLoc> PutVal = Call.getArgSVal(0).getAs<NonLoc>();
775+
if (!PutVal)
776+
return;
777+
ProgramStateRef StateNotFailed =
778+
State->BindExpr(CE, C.getLocationContext(), *PutVal);
779+
StateNotFailed =
780+
StateNotFailed->set<StreamMap>(StreamSym, StreamState::getOpened(Desc));
781+
C.addTransition(StateNotFailed);
782+
783+
// Add transition for the failed state.
784+
// If a (non-EOF) error occurs, the resulting value of the file position
785+
// indicator for the stream is indeterminate.
786+
ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
787+
StreamState NewSS = StreamState::getOpened(
788+
Desc, ErrorFError, /*IsFilePositionIndeterminate*/ true);
789+
StateFailed = StateFailed->set<StreamMap>(StreamSym, NewSS);
790+
C.addTransition(StateFailed);
791+
}
792+
748793
void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
749794
CheckerContext &C) const {
750795
ProgramStateRef State = C.getState();

clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ ProgramStateRef VLASizeChecker::checkVLAIndexSize(CheckerContext &C,
188188
QualType SizeTy = SizeE->getType();
189189
DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
190190

191-
SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
191+
SVal LessThanZeroVal =
192+
SVB.evalBinOp(State, BO_LT, SizeD, Zero, SVB.getConditionType());
192193
if (std::optional<DefinedSVal> LessThanZeroDVal =
193194
LessThanZeroVal.getAs<DefinedSVal>()) {
194195
ConstraintManager &CM = C.getConstraintManager();

clang/lib/Support/RISCVVIntrinsicUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ void RVVType::applyModifier(const PrototypeDescriptor &Transformer) {
857857
case TypeModifier::Float:
858858
ScalarType = ScalarTypeKind::Float;
859859
break;
860+
case TypeModifier::BFloat:
861+
ScalarType = ScalarTypeKind::BFloat;
862+
break;
860863
case TypeModifier::LMUL1:
861864
LMUL = LMULType(0);
862865
// Update ElementBitwidth need to update Scale too.

clang/test/Analysis/stream-error.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ void error_fwrite(void) {
101101
Ret = fwrite(0, 1, 10, F); // expected-warning {{Stream might be already closed}}
102102
}
103103

104+
void error_fputc(void) {
105+
FILE *F = tmpfile();
106+
if (!F)
107+
return;
108+
int Ret = fputc('X', F);
109+
if (Ret == EOF) {
110+
clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
111+
clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
112+
fputc('Y', F); // expected-warning {{might be 'indeterminate'}}
113+
} else {
114+
clang_analyzer_eval(Ret == 'X'); // expected-warning {{TRUE}}
115+
clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
116+
fputc('Y', F); // no-warning
117+
}
118+
fclose(F);
119+
fputc('A', F); // expected-warning {{Stream might be already closed}}
120+
}
121+
104122
void freadwrite_zerosize(FILE *F) {
105123
size_t Ret;
106124
Ret = fwrite(0, 1, 0, F);
@@ -241,6 +259,23 @@ void error_indeterminate_clearerr(void) {
241259
fclose(F);
242260
}
243261

262+
void error_indeterminate_fputc(void) {
263+
FILE *F = fopen("file", "r+");
264+
if (!F)
265+
return;
266+
int rc = fseek(F, 0, SEEK_SET);
267+
if (rc) {
268+
if (feof(F)) {
269+
fputc('X', F); // no warning
270+
} else if (ferror(F)) {
271+
fputc('C', F); // expected-warning {{might be 'indeterminate'}}
272+
} else {
273+
fputc('E', F); // expected-warning {{might be 'indeterminate'}}
274+
}
275+
}
276+
fclose(F);
277+
}
278+
244279
void error_indeterminate_feof1(void) {
245280
FILE *F = fopen("file", "r+");
246281
if (!F)

clang/test/Analysis/stream.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ void check_fwrite(void) {
1414
fclose(fp);
1515
}
1616

17+
void check_fputc(void) {
18+
FILE *fp = tmpfile();
19+
fputc('A', fp); // expected-warning {{Stream pointer might be NULL}}
20+
fclose(fp);
21+
}
22+
1723
void check_fseek(void) {
1824
FILE *fp = tmpfile();
1925
fseek(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}}

0 commit comments

Comments
 (0)