Skip to content

Commit afee350

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:381efa496000 into amd-gfx:df4f5070dfea
Local branch amd-gfx df4f507 Merged main:0bc7cd4d5122 into amd-gfx:94601047c932 Remote branch main 381efa4 Revert rG67275263b3b781a "[X86] X86DAGToDAGISel - attempt to merge XMM/YMM loads with YMM/ZMM loads of the same ptr (llvm#73126)"
2 parents df4f507 + 381efa4 commit afee350

File tree

91 files changed

+7573
-7309
lines changed

Some content is hidden

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

91 files changed

+7573
-7309
lines changed

clang/include/clang/Basic/Cuda.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ enum class CudaArch {
113113
GFX1103,
114114
GFX1150,
115115
GFX1151,
116+
GFX1200,
117+
GFX1201,
116118
Generic, // A processor model named 'generic' if the target backend defines a
117119
// public one.
118120
LAST,

clang/lib/Basic/Cuda.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ static const CudaArchToStringMap arch_names[] = {
135135
GFX(1103), // gfx1103
136136
GFX(1150), // gfx1150
137137
GFX(1151), // gfx1151
138+
GFX(1200), // gfx1200
139+
GFX(1201), // gfx1201
138140
{CudaArch::Generic, "generic", ""},
139141
// clang-format on
140142
};

clang/lib/Basic/Targets/NVPTX.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
214214
case CudaArch::GFX1103:
215215
case CudaArch::GFX1150:
216216
case CudaArch::GFX1151:
217+
case CudaArch::GFX1200:
218+
case CudaArch::GFX1201:
217219
case CudaArch::Generic:
218220
case CudaArch::LAST:
219221
break;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,12 +5745,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
57455745
Address DestAddr = EmitMSVAListRef(E->getArg(0));
57465746
Address SrcAddr = EmitMSVAListRef(E->getArg(1));
57475747

5748-
llvm::Type *BPP = Int8PtrPtrTy;
5749-
5750-
DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"),
5751-
Int8PtrTy, DestAddr.getAlignment());
5752-
SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"),
5753-
Int8PtrTy, SrcAddr.getAlignment());
5748+
DestAddr = DestAddr.withElementType(Int8PtrTy);
5749+
SrcAddr = SrcAddr.withElementType(Int8PtrTy);
57545750

57555751
Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val");
57565752
return RValue::get(Builder.CreateStore(ArgPtr, DestAddr));
@@ -8424,8 +8420,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
84248420
}
84258421

84268422
Value *LdPtr = EmitScalarExpr(E->getArg(0));
8427-
Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy),
8428-
"ldrexd");
8423+
Value *Val = Builder.CreateCall(F, LdPtr, "ldrexd");
84298424

84308425
Value *Val0 = Builder.CreateExtractValue(Val, 1);
84318426
Value *Val1 = Builder.CreateExtractValue(Val, 0);
@@ -8483,7 +8478,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
84838478

84848479
Value *Arg0 = Builder.CreateExtractValue(Val, 0);
84858480
Value *Arg1 = Builder.CreateExtractValue(Val, 1);
8486-
Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), Int8PtrTy);
8481+
Value *StPtr = EmitScalarExpr(E->getArg(1));
84878482
return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd");
84888483
}
84898484

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,29 +1244,24 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D,
12441244
// If the initializer is small, use a handful of stores.
12451245
if (shouldSplitConstantStore(CGM, ConstantSize)) {
12461246
if (auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1247-
// FIXME: handle the case when STy != Loc.getElementType().
1248-
if (STy == Loc.getElementType()) {
1249-
for (unsigned i = 0; i != constant->getNumOperands(); i++) {
1250-
Address EltPtr = Builder.CreateStructGEP(Loc, i);
1251-
emitStoresForConstant(
1252-
CGM, D, EltPtr, isVolatile, Builder,
1253-
cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)),
1254-
IsAutoInit);
1255-
}
1256-
return;
1247+
const llvm::StructLayout *Layout =
1248+
CGM.getDataLayout().getStructLayout(STy);
1249+
for (unsigned i = 0; i != constant->getNumOperands(); i++) {
1250+
CharUnits CurOff = CharUnits::fromQuantity(Layout->getElementOffset(i));
1251+
Address EltPtr = Builder.CreateConstInBoundsByteGEP(
1252+
Loc.withElementType(CGM.Int8Ty), CurOff);
1253+
emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
1254+
constant->getAggregateElement(i), IsAutoInit);
12571255
}
1256+
return;
12581257
} else if (auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1259-
// FIXME: handle the case when ATy != Loc.getElementType().
1260-
if (ATy == Loc.getElementType()) {
1261-
for (unsigned i = 0; i != ATy->getNumElements(); i++) {
1262-
Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
1263-
emitStoresForConstant(
1264-
CGM, D, EltPtr, isVolatile, Builder,
1265-
cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)),
1266-
IsAutoInit);
1267-
}
1268-
return;
1258+
for (unsigned i = 0; i != ATy->getNumElements(); i++) {
1259+
Address EltPtr = Builder.CreateConstGEP(
1260+
Loc.withElementType(ATy->getElementType()), i);
1261+
emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
1262+
constant->getAggregateElement(i), IsAutoInit);
12691263
}
1264+
return;
12701265
}
12711266
}
12721267

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,7 @@ class ConstantLValueEmitter : public ConstStmtVisitor<ConstantLValueEmitter,
18611861
if (!hasNonZeroOffset())
18621862
return C;
18631863

1864-
llvm::Type *origPtrTy = C->getType();
1865-
C = llvm::ConstantExpr::getGetElementPtr(CGM.Int8Ty, C, getOffset());
1866-
C = llvm::ConstantExpr::getPointerCast(C, origPtrTy);
1867-
return C;
1864+
return llvm::ConstantExpr::getGetElementPtr(CGM.Int8Ty, C, getOffset());
18681865
}
18691866
};
18701867

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,8 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(
35403540
case CudaArch::GFX1103:
35413541
case CudaArch::GFX1150:
35423542
case CudaArch::GFX1151:
3543+
case CudaArch::GFX1200:
3544+
case CudaArch::GFX1201:
35433545
case CudaArch::Generic:
35443546
case CudaArch::UNUSED:
35453547
case CudaArch::UNKNOWN:

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
12991299
SLocPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
13001300
CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
13011301
assert(ReturnLocation.isValid() && "No valid return location");
1302-
Builder.CreateStore(Builder.CreateBitCast(SLocPtr, Int8PtrTy),
1303-
ReturnLocation);
1302+
Builder.CreateStore(SLocPtr, ReturnLocation);
13041303
}
13051304

13061305
// Returning from an outlined SEH helper is UB, and we already warn on it.

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,12 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
250250
{{{"fwrite"}, 4},
251251
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
252252
std::bind(&StreamChecker::evalFreadFwrite, _1, _2, _3, _4, false), 3}},
253+
{{{"fgetc"}, 1},
254+
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
255+
std::bind(&StreamChecker::evalFgetcFputc, _1, _2, _3, _4, true), 0}},
253256
{{{"fputc"}, 2},
254257
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
255-
&StreamChecker::evalFputc, 1}},
258+
std::bind(&StreamChecker::evalFgetcFputc, _1, _2, _3, _4, false), 1}},
256259
{{{"fseek"}, 3},
257260
{&StreamChecker::preFseek, &StreamChecker::evalFseek, 0}},
258261
{{{"ftell"}, 1},
@@ -314,8 +317,8 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
314317
void evalFreadFwrite(const FnDescription *Desc, const CallEvent &Call,
315318
CheckerContext &C, bool IsFread) const;
316319

317-
void evalFputc(const FnDescription *Desc, const CallEvent &Call,
318-
CheckerContext &C) const;
320+
void evalFgetcFputc(const FnDescription *Desc, const CallEvent &Call,
321+
CheckerContext &C, bool IsRead) const;
319322

320323
void preFseek(const FnDescription *Desc, const CallEvent &Call,
321324
CheckerContext &C) const;
@@ -751,8 +754,9 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
751754
C.addTransition(StateFailed);
752755
}
753756

754-
void StreamChecker::evalFputc(const FnDescription *Desc, const CallEvent &Call,
755-
CheckerContext &C) const {
757+
void StreamChecker::evalFgetcFputc(const FnDescription *Desc,
758+
const CallEvent &Call, CheckerContext &C,
759+
bool IsRead) const {
756760
ProgramStateRef State = C.getState();
757761
SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
758762
if (!StreamSym)
@@ -768,26 +772,70 @@ void StreamChecker::evalFputc(const FnDescription *Desc, const CallEvent &Call,
768772

769773
assertStreamStateOpened(OldSS);
770774

775+
// `fgetc` returns the read character on success, otherwise returns EOF.
771776
// `fputc` returns the written character on success, otherwise returns EOF.
772777

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);
778+
// Generate a transition for the success state of fputc.
779+
if (!IsRead) {
780+
std::optional<NonLoc> PutVal = Call.getArgSVal(0).getAs<NonLoc>();
781+
if (!PutVal)
782+
return;
783+
ProgramStateRef StateNotFailed =
784+
State->BindExpr(CE, C.getLocationContext(), *PutVal);
785+
StateNotFailed =
786+
StateNotFailed->set<StreamMap>(StreamSym, StreamState::getOpened(Desc));
787+
C.addTransition(StateNotFailed);
788+
}
789+
// Generate a transition for the success state of fgetc.
790+
// If we know the state to be FEOF at fgetc, do not add a success state.
791+
else if (OldSS->ErrorState != ErrorFEof) {
792+
NonLoc RetVal = makeRetVal(C, CE).castAs<NonLoc>();
793+
ProgramStateRef StateNotFailed =
794+
State->BindExpr(CE, C.getLocationContext(), RetVal);
795+
SValBuilder &SVB = C.getSValBuilder();
796+
auto &ASTC = C.getASTContext();
797+
// The returned 'unsigned char' of `fgetc` is converted to 'int',
798+
// so we need to check if it is in range [0, 255].
799+
auto CondLow =
800+
SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ASTC.IntTy),
801+
SVB.getConditionType())
802+
.getAs<DefinedOrUnknownSVal>();
803+
auto CondHigh =
804+
SVB.evalBinOp(State, BO_LE, RetVal,
805+
SVB.makeIntVal(SVB.getBasicValueFactory()
806+
.getMaxValue(ASTC.UnsignedCharTy)
807+
.getLimitedValue(),
808+
ASTC.IntTy),
809+
SVB.getConditionType())
810+
.getAs<DefinedOrUnknownSVal>();
811+
if (!CondLow || !CondHigh)
812+
return;
813+
StateNotFailed = StateNotFailed->assume(*CondLow, true);
814+
if (!StateNotFailed)
815+
return;
816+
StateNotFailed = StateNotFailed->assume(*CondHigh, true);
817+
if (!StateNotFailed)
818+
return;
819+
C.addTransition(StateNotFailed);
820+
}
782821

783822
// Add transition for the failed state.
823+
ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
824+
784825
// If a (non-EOF) error occurs, the resulting value of the file position
785826
// indicator for the stream is indeterminate.
786-
ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
787-
StreamState NewSS = StreamState::getOpened(
788-
Desc, ErrorFError, /*IsFilePositionIndeterminate*/ true);
827+
StreamErrorState NewES;
828+
if (IsRead)
829+
NewES =
830+
OldSS->ErrorState == ErrorFEof ? ErrorFEof : ErrorFEof | ErrorFError;
831+
else
832+
NewES = ErrorFError;
833+
StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
789834
StateFailed = StateFailed->set<StreamMap>(StreamSym, NewSS);
790-
C.addTransition(StateFailed);
835+
if (IsRead && OldSS->ErrorState != ErrorFEof)
836+
C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
837+
else
838+
C.addTransition(StateFailed);
791839
}
792840

793841
void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,

clang/test/Analysis/Inputs/system-header-simulator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE *re
4848
int fclose(FILE *fp);
4949
size_t fread(void *restrict, size_t, size_t, FILE *restrict);
5050
size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
51+
int fgetc(FILE *stream);
5152
int fputc(int ch, FILE *stream);
5253
int fseek(FILE *__stream, long int __off, int __whence);
5354
long int ftell(FILE *__stream);

clang/test/Analysis/stream-error.c

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

104+
void error_fgetc(void) {
105+
FILE *F = tmpfile();
106+
if (!F)
107+
return;
108+
int Ret = fgetc(F);
109+
if (0 <= Ret && Ret <= 255) {
110+
clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
111+
} else {
112+
clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
113+
clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{TRUE}}
114+
if (feof(F)) {
115+
clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
116+
fgetc(F); // expected-warning {{Read function called when stream is in EOF state}}
117+
} else {
118+
clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
119+
fgetc(F); // expected-warning {{might be 'indeterminate'}}
120+
}
121+
}
122+
fclose(F);
123+
fgetc(F); // expected-warning {{Stream might be already closed}}
124+
}
125+
104126
void error_fputc(void) {
105127
FILE *F = tmpfile();
106128
if (!F)
@@ -259,23 +281,6 @@ void error_indeterminate_clearerr(void) {
259281
fclose(F);
260282
}
261283

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-
279284
void error_indeterminate_feof1(void) {
280285
FILE *F = fopen("file", "r+");
281286
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_fgetc(void) {
18+
FILE *fp = tmpfile();
19+
fgetc(fp); // expected-warning {{Stream pointer might be NULL}}
20+
fclose(fp);
21+
}
22+
1723
void check_fputc(void) {
1824
FILE *fp = tmpfile();
1925
fputc('A', fp); // expected-warning {{Stream pointer might be NULL}}

0 commit comments

Comments
 (0)