Skip to content

Commit 6e535f3

Browse files
committed
format
1 parent 8450816 commit 6e535f3

File tree

12 files changed

+219
-228
lines changed

12 files changed

+219
-228
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,9 @@ class Expr : public ValueStmt {
787787
const Expr *PtrExpression, ASTContext &Ctx,
788788
EvalResult &Status) const;
789789

790-
bool EvaluateCharRangeAsString(APValue &Result,
791-
const Expr *SizeExpression,
792-
const Expr *PtrExpression, ASTContext &Ctx,
793-
EvalResult &Status) const;
790+
bool EvaluateCharRangeAsString(APValue &Result, const Expr *SizeExpression,
791+
const Expr *PtrExpression, ASTContext &Ctx,
792+
EvalResult &Status) const;
794793

795794
/// If the current Expr can be evaluated to a pointer to a null-terminated
796795
/// constant string, return the constant string (without the terminating

clang/include/clang/AST/Stmt.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,9 +3314,8 @@ class GCCAsmStmt : public AsmStmt {
33143314
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
33153315
bool isvolatile, unsigned numoutputs, unsigned numinputs,
33163316
IdentifierInfo **names, Expr **constraints, Expr **exprs,
3317-
Expr *asmstr, unsigned numclobbers,
3318-
Expr **clobbers, unsigned numlabels,
3319-
SourceLocation rparenloc);
3317+
Expr *asmstr, unsigned numclobbers, Expr **clobbers,
3318+
unsigned numlabels, SourceLocation rparenloc);
33203319

33213320
/// Build an empty inline-assembly statement.
33223321
explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
@@ -3404,9 +3403,7 @@ class GCCAsmStmt : public AsmStmt {
34043403
const Expr *getOutputConstraintExpr(unsigned i) const {
34053404
return Constraints[i];
34063405
}
3407-
Expr *getOutputConstraintExpr(unsigned i) {
3408-
return Constraints[i];
3409-
}
3406+
Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; }
34103407

34113408
Expr *getOutputExpr(unsigned i);
34123409

@@ -3443,7 +3440,7 @@ class GCCAsmStmt : public AsmStmt {
34433440
return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
34443441
}
34453442

3446-
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr* E);
3443+
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E);
34473444

34483445
//===--- Labels ---===//
34493446

@@ -3493,12 +3490,9 @@ class GCCAsmStmt : public AsmStmt {
34933490
private:
34943491
void setOutputsAndInputsAndClobbers(const ASTContext &C,
34953492
IdentifierInfo **Names,
3496-
Expr **Constraints,
3497-
Stmt **Exprs,
3498-
unsigned NumOutputs,
3499-
unsigned NumInputs,
3500-
unsigned NumLabels,
3501-
Expr **Clobbers,
3493+
Expr **Constraints, Stmt **Exprs,
3494+
unsigned NumOutputs, unsigned NumInputs,
3495+
unsigned NumLabels, Expr **Clobbers,
35023496
unsigned NumClobbers);
35033497

35043498
public:
@@ -3512,9 +3506,7 @@ class GCCAsmStmt : public AsmStmt {
35123506
std::string getClobber(unsigned i) const;
35133507

35143508
Expr *getClobberExpr(unsigned i) { return Clobbers[i]; }
3515-
const Expr *getClobberExpr(unsigned i) const {
3516-
return Clobbers[i];
3517-
}
3509+
const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; }
35183510

35193511
SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
35203512
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,10 +5585,7 @@ class Sema final : public SemaBase {
55855585
void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
55865586
void ActOnFinishDelayedMemberInitializers(Decl *Record);
55875587

5588-
enum class StringEvaluationContext {
5589-
StaticAssert = 0,
5590-
Asm = 1
5591-
};
5588+
enum class StringEvaluationContext { StaticAssert = 0, Asm = 1 };
55925589

55935590
bool EvaluateAsString(Expr *Message, APValue &Result, ASTContext &Ctx,
55945591
StringEvaluationContext EvalContext,
@@ -11049,7 +11046,7 @@ class Sema final : public SemaBase {
1104911046
///@{
1105011047

1105111048
public:
11052-
ExprResult ActOnGCCAsmStmtString(Expr* Stm, bool ForAsmLabel);
11049+
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel);
1105311050
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1105411051
bool IsVolatile, unsigned NumOutputs,
1105511052
unsigned NumInputs, IdentifierInfo **Names,
@@ -15339,14 +15336,12 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
1533915336
llvm::StringRef StackSlotLabel,
1534015337
AlignPackInfo Value);
1534115338

15342-
inline
15343-
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
15344-
Sema::StringEvaluationContext Ctx) {
15339+
inline const StreamingDiagnostic &
15340+
operator<<(const StreamingDiagnostic &DB, Sema::StringEvaluationContext Ctx) {
1534515341
DB << llvm::to_underlying(Ctx);
1534615342
return DB;
1534715343
}
1534815344

15349-
1535015345
} // end namespace clang
1535115346

1535215347
#endif

clang/lib/AST/ExprConstant.cpp

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17929,69 +17929,70 @@ std::optional<std::string> Expr::tryEvaluateString(ASTContext &Ctx) const {
1792917929
}
1793017930

1793117931
template <typename T>
17932-
static bool EvaluateCharRangeAsStringImpl(const Expr*, T& Result,
17932+
static bool EvaluateCharRangeAsStringImpl(const Expr *, T &Result,
1793317933
const Expr *SizeExpression,
17934-
const Expr *PtrExpression, ASTContext &Ctx,
17934+
const Expr *PtrExpression,
17935+
ASTContext &Ctx,
1793517936
Expr::EvalResult &Status) {
17936-
LValue String;
17937-
EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
17938-
Info.InConstantContext = true;
17939-
17940-
FullExpressionRAII Scope(Info);
17941-
APSInt SizeValue;
17942-
if (!::EvaluateInteger(SizeExpression, SizeValue, Info))
17943-
return false;
17937+
LValue String;
17938+
EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
17939+
Info.InConstantContext = true;
1794417940

17945-
uint64_t Size = SizeValue.getZExtValue();
17941+
FullExpressionRAII Scope(Info);
17942+
APSInt SizeValue;
17943+
if (!::EvaluateInteger(SizeExpression, SizeValue, Info))
17944+
return false;
1794617945

17947-
if constexpr(std::is_same_v<APValue, T>)
17948-
Result = APValue(APValue::UninitArray{}, Size, Size);
17949-
//else
17950-
// Result.reserve(Size);
17946+
uint64_t Size = SizeValue.getZExtValue();
1795117947

17952-
if (!::EvaluatePointer(PtrExpression, String, Info))
17953-
return false;
17948+
if constexpr (std::is_same_v<APValue, T>)
17949+
Result = APValue(APValue::UninitArray{}, Size, Size);
17950+
// else
17951+
// Result.reserve(Size);
1795417952

17955-
QualType CharTy = PtrExpression->getType()->getPointeeType();
17956-
for (uint64_t I = 0; I < Size; ++I) {
17957-
APValue Char;
17958-
if (!handleLValueToRValueConversion(Info, PtrExpression, CharTy, String,
17959-
Char))
17960-
return false;
17953+
if (!::EvaluatePointer(PtrExpression, String, Info))
17954+
return false;
1796117955

17962-
if constexpr(std::is_same_v<APValue, T>) {
17963-
Result.getArrayInitializedElt(I) = std::move(Char);
17964-
}
17965-
else {
17966-
APSInt C = Char.getInt();
17967-
Result.push_back(static_cast<char>(C.getExtValue()));
17968-
}
17956+
QualType CharTy = PtrExpression->getType()->getPointeeType();
17957+
for (uint64_t I = 0; I < Size; ++I) {
17958+
APValue Char;
17959+
if (!handleLValueToRValueConversion(Info, PtrExpression, CharTy, String,
17960+
Char))
17961+
return false;
1796917962

17970-
if (!HandleLValueArrayAdjustment(Info, PtrExpression, String, CharTy, 1))
17971-
return false;
17963+
if constexpr (std::is_same_v<APValue, T>) {
17964+
Result.getArrayInitializedElt(I) = std::move(Char);
17965+
} else {
17966+
APSInt C = Char.getInt();
17967+
Result.push_back(static_cast<char>(C.getExtValue()));
1797217968
}
17973-
if (!Scope.destroy())
17974-
return false;
1797517969

17976-
if (!CheckMemoryLeaks(Info))
17970+
if (!HandleLValueArrayAdjustment(Info, PtrExpression, String, CharTy, 1))
1797717971
return false;
17972+
}
17973+
if (!Scope.destroy())
17974+
return false;
1797817975

17979-
return true;
17980-
}
17976+
if (!CheckMemoryLeaks(Info))
17977+
return false;
1798117978

17979+
return true;
17980+
}
1798217981

1798317982
bool Expr::EvaluateCharRangeAsString(std::string &Result,
1798417983
const Expr *SizeExpression,
1798517984
const Expr *PtrExpression, ASTContext &Ctx,
1798617985
EvalResult &Status) const {
17987-
return EvaluateCharRangeAsStringImpl(this, Result, SizeExpression, PtrExpression, Ctx, Status);
17986+
return EvaluateCharRangeAsStringImpl(this, Result, SizeExpression,
17987+
PtrExpression, Ctx, Status);
1798817988
}
1798917989

1799017990
bool Expr::EvaluateCharRangeAsString(APValue &Result,
17991-
const Expr *SizeExpression,
17992-
const Expr *PtrExpression, ASTContext &Ctx,
17993-
EvalResult &Status) const {
17994-
return EvaluateCharRangeAsStringImpl(this, Result, SizeExpression, PtrExpression, Ctx, Status);
17991+
const Expr *SizeExpression,
17992+
const Expr *PtrExpression, ASTContext &Ctx,
17993+
EvalResult &Status) const {
17994+
return EvaluateCharRangeAsStringImpl(this, Result, SizeExpression,
17995+
PtrExpression, Ctx, Status);
1799517996
}
1799617997

1799717998
bool Expr::tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const {

clang/lib/AST/Stmt.cpp

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,18 @@ char GCCAsmStmt::AsmStringPiece::getModifier() const {
510510
return isLetter(Str[0]) ? Str[0] : '\0';
511511
}
512512

513-
std::string GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(const Expr* E) {
514-
if(auto* SL = llvm::dyn_cast<StringLiteral>(E))
513+
std::string GCCAsmStmt::ExtractStringFromGCCAsmStmtComponent(const Expr *E) {
514+
if (auto *SL = llvm::dyn_cast<StringLiteral>(E))
515515
return SL->getString().str();
516-
assert(E->getDependence() == ExprDependence::None && "cannot extract a string from a dependent expression");
517-
auto* CE = cast<ConstantExpr>(E);
516+
assert(E->getDependence() == ExprDependence::None &&
517+
"cannot extract a string from a dependent expression");
518+
auto *CE = cast<ConstantExpr>(E);
518519
APValue Res = CE->getAPValueResult();
519520
assert(Res.isArray() && "expected an array");
520521

521522
std::string Out;
522523
Out.reserve(Res.getArraySize());
523-
for(unsigned I = 0; I < Res.getArraySize(); ++I) {
524+
for (unsigned I = 0; I < Res.getArraySize(); ++I) {
524525
APValue C = Res.getArrayInitializedElt(I);
525526
assert(C.isInt());
526527
auto Ch = static_cast<char>(C.getInt().getExtValue());
@@ -570,15 +571,10 @@ std::string GCCAsmStmt::getInputConstraint(unsigned i) const {
570571
return ExtractStringFromGCCAsmStmtComponent(getInputConstraintExpr(i));
571572
}
572573

573-
void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
574-
IdentifierInfo **Names,
575-
Expr **Constraints,
576-
Stmt **Exprs,
577-
unsigned NumOutputs,
578-
unsigned NumInputs,
579-
unsigned NumLabels,
580-
Expr **Clobbers,
581-
unsigned NumClobbers) {
574+
void GCCAsmStmt::setOutputsAndInputsAndClobbers(
575+
const ASTContext &C, IdentifierInfo **Names, Expr **Constraints,
576+
Stmt **Exprs, unsigned NumOutputs, unsigned NumInputs, unsigned NumLabels,
577+
Expr **Clobbers, unsigned NumClobbers) {
582578
this->NumOutputs = NumOutputs;
583579
this->NumInputs = NumInputs;
584580
this->NumClobbers = NumClobbers;
@@ -596,11 +592,11 @@ void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
596592

597593
unsigned NumConstraints = NumOutputs + NumInputs;
598594
C.Deallocate(this->Constraints);
599-
this->Constraints = new (C) Expr*[NumConstraints];
595+
this->Constraints = new (C) Expr *[NumConstraints];
600596
std::copy(Constraints, Constraints + NumConstraints, this->Constraints);
601597

602598
C.Deallocate(this->Clobbers);
603-
this->Clobbers = new (C) Expr*[NumClobbers];
599+
this->Clobbers = new (C) Expr *[NumClobbers];
604600
std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
605601
}
606602

@@ -766,15 +762,14 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
766762
// (BeginLoc, EndLoc) represents the range of the operand we are currently
767763
// processing. Unlike Str, the range includes the leading '%'.
768764
SourceLocation BeginLoc, EndLoc;
769-
if(auto* SL = dyn_cast<StringLiteral>(getAsmStringExpr())) {
770-
BeginLoc = SL->getLocationOfByte(
771-
Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
772-
&LastAsmStringOffset);
773-
EndLoc = SL->getLocationOfByte(
774-
CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
775-
&LastAsmStringOffset);
776-
}
777-
else {
765+
if (auto *SL = dyn_cast<StringLiteral>(getAsmStringExpr())) {
766+
BeginLoc =
767+
SL->getLocationOfByte(Percent - StrStart, SM, LO, TI,
768+
&LastAsmStringToken, &LastAsmStringOffset);
769+
EndLoc =
770+
SL->getLocationOfByte(CurPtr - StrStart, SM, LO, TI,
771+
&LastAsmStringToken, &LastAsmStringOffset);
772+
} else {
778773
BeginLoc = getAsmStringExpr()->getBeginLoc();
779774
EndLoc = getAsmStringExpr()->getEndLoc();
780775
}
@@ -809,15 +804,14 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
809804
// (BeginLoc, EndLoc) represents the range of the operand we are currently
810805
// processing. Unlike Str, the range includes the leading '%'.
811806
SourceLocation BeginLoc, EndLoc;
812-
if(auto* SL = dyn_cast<StringLiteral>(getAsmStringExpr())) {
813-
BeginLoc = SL->getLocationOfByte(
814-
Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
815-
&LastAsmStringOffset);
816-
EndLoc = SL->getLocationOfByte(
817-
NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
818-
&LastAsmStringOffset);
819-
}
820-
else {
807+
if (auto *SL = dyn_cast<StringLiteral>(getAsmStringExpr())) {
808+
BeginLoc =
809+
SL->getLocationOfByte(Percent - StrStart, SM, LO, TI,
810+
&LastAsmStringToken, &LastAsmStringOffset);
811+
EndLoc =
812+
SL->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI,
813+
&LastAsmStringToken, &LastAsmStringOffset);
814+
} else {
821815
BeginLoc = getAsmStringExpr()->getBeginLoc();
822816
EndLoc = getAsmStringExpr()->getEndLoc();
823817
}
@@ -900,13 +894,12 @@ void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
900894
GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
901895
bool issimple, bool isvolatile, unsigned numoutputs,
902896
unsigned numinputs, IdentifierInfo **names,
903-
Expr **constraints, Expr **exprs,
904-
Expr *asmstr, unsigned numclobbers,
905-
Expr **clobbers, unsigned numlabels,
906-
SourceLocation rparenloc)
897+
Expr **constraints, Expr **exprs, Expr *asmstr,
898+
unsigned numclobbers, Expr **clobbers,
899+
unsigned numlabels, SourceLocation rparenloc)
907900
: AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
908901
numinputs, numclobbers),
909-
RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
902+
RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
910903
unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
911904

912905
Names = new (C) IdentifierInfo*[NumExprs];
@@ -916,10 +909,10 @@ GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
916909
std::copy(exprs, exprs + NumExprs, Exprs);
917910

918911
unsigned NumConstraints = NumOutputs + NumInputs;
919-
Constraints = new (C) Expr*[NumConstraints];
912+
Constraints = new (C) Expr *[NumConstraints];
920913
std::copy(constraints, constraints + NumConstraints, Constraints);
921914

922-
Clobbers = new (C) Expr*[NumClobbers];
915+
Clobbers = new (C) Expr *[NumClobbers];
923916
std::copy(clobbers, clobbers + NumClobbers, Clobbers);
924917
}
925918

clang/lib/AST/StmtPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
497497
if (Policy.IncludeNewlines) OS << NL;
498498
}
499499

500-
static void PrintGCCAsmString(raw_ostream &OS, Expr*E) {
501-
if(E->getDependence()) {
500+
static void PrintGCCAsmString(raw_ostream &OS, Expr *E) {
501+
if (E->getDependence()) {
502502
OS << "<<dependent expr>>";
503503
return;
504504
}

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,11 +2587,10 @@ static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect,
25872587
// Slap the source location of the inline asm into a !srcloc metadata on the
25882588
// call.
25892589
if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(&S)) {
2590-
if(const StringLiteral* SL = dyn_cast<StringLiteral>(gccAsmStmt->getAsmStringExpr()))
2591-
Result.setMetadata("srcloc",
2592-
getAsmSrcLocInfo(SL, CGF));
2593-
}
2594-
else {
2590+
if (const StringLiteral *SL =
2591+
dyn_cast<StringLiteral>(gccAsmStmt->getAsmStringExpr()))
2592+
Result.setMetadata("srcloc", getAsmSrcLocInfo(SL, CGF));
2593+
} else {
25952594
// At least put the line number on MS inline asm blobs.
25962595
llvm::Constant *Loc =
25972596
llvm::ConstantInt::get(CGF.Int64Ty, S.getAsmLoc().getRawEncoding());

0 commit comments

Comments
 (0)