Skip to content

Commit 509a048

Browse files
authored
Merge branch 'main' into assume-filename-with-clang-format-ignore
2 parents 96811d0 + d906ac5 commit 509a048

File tree

100 files changed

+1184
-598
lines changed

Some content is hidden

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

100 files changed

+1184
-598
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,13 @@ class CXXTypeidExpr : public Expr {
876876

877877
/// Best-effort check if the expression operand refers to a most derived
878878
/// object. This is not a strong guarantee.
879-
bool isMostDerived(ASTContext &Context) const;
879+
bool isMostDerived(const ASTContext &Context) const;
880880

881881
bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
882882

883883
/// Retrieves the type operand of this typeid() expression after
884884
/// various required adjustments (removing reference types, cv-qualifiers).
885-
QualType getTypeOperand(ASTContext &Context) const;
885+
QualType getTypeOperand(const ASTContext &Context) const;
886886

887887
/// Retrieve source information for the type operand.
888888
TypeSourceInfo *getTypeOperandSourceInfo() const {

clang/include/clang/ASTMatchers/ASTMatchersMacros.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
5050
#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
5151

52+
#include "clang/Support/Compiler.h"
53+
5254
/// AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) { ... }
5355
/// defines a zero parameter function named DefineMatcher() that returns a
5456
/// ReturnType object.
@@ -367,7 +369,7 @@
367369
static QualType (T::*value())() const { return &T::FunctionName; } \
368370
}; \
369371
} \
370-
extern const ::clang::ast_matchers::internal:: \
372+
CLANG_ABI extern const ::clang::ast_matchers::internal:: \
371373
TypeTraversePolymorphicMatcher< \
372374
QualType, \
373375
::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
@@ -407,7 +409,7 @@
407409
static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
408410
}; \
409411
} \
410-
extern const ::clang::ast_matchers::internal:: \
412+
CLANG_ABI extern const ::clang::ast_matchers::internal:: \
411413
TypeTraversePolymorphicMatcher< \
412414
TypeLoc, \
413415
::clang::ast_matchers::internal:: \

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum class FloatModeKind {
8787
struct TransferrableTargetInfo {
8888
unsigned char PointerWidth, PointerAlign;
8989
unsigned char BoolWidth, BoolAlign;
90+
unsigned char ShortWidth, ShortAlign;
9091
unsigned char IntWidth, IntAlign;
9192
unsigned char HalfWidth, HalfAlign;
9293
unsigned char BFloat16Width, BFloat16Align;
@@ -497,13 +498,10 @@ class TargetInfo : public TransferrableTargetInfo,
497498
unsigned getCharWidth() const { return 8; } // FIXME
498499
unsigned getCharAlign() const { return 8; } // FIXME
499500

500-
/// Return the size of 'signed short' and 'unsigned short' for this
501-
/// target, in bits.
502-
unsigned getShortWidth() const { return 16; } // FIXME
503-
504-
/// Return the alignment of 'signed short' and 'unsigned short' for
505-
/// this target.
506-
unsigned getShortAlign() const { return 16; } // FIXME
501+
/// getShortWidth/Align - Return the size of 'signed short' and
502+
/// 'unsigned short' for this target, in bits.
503+
unsigned getShortWidth() const { return ShortWidth; }
504+
unsigned getShortAlign() const { return ShortAlign; }
507505

508506
/// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
509507
/// this target, in bits.

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5738,9 +5738,17 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
57385738
// We should already have a pointer when we get here.
57395739
return this->delegate(SubExpr);
57405740
case UO_Deref: // *x
5741-
if (DiscardResult)
5741+
if (DiscardResult) {
5742+
// assert(false);
57425743
return this->discard(SubExpr);
5743-
return this->visit(SubExpr);
5744+
}
5745+
5746+
if (!this->visit(SubExpr))
5747+
return false;
5748+
if (classifyPrim(SubExpr) == PT_Ptr)
5749+
return this->emitNarrowPtr(E);
5750+
return true;
5751+
57445752
case UO_Not: // ~x
57455753
if (!T)
57465754
return this->emitError(E);
@@ -6089,7 +6097,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60896097

60906098
if (VD->evaluateValue())
60916099
return revisit(VD);
6092-
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), E);
6100+
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
6101+
/*InitializerFailed=*/true, E);
60936102
}
60946103
}
60956104
} else {
@@ -6115,7 +6124,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
61156124
}
61166125

61176126
if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
6118-
return this->emitInvalidDeclRef(DRE, E);
6127+
return this->emitInvalidDeclRef(DRE, /*InitializerFailed=*/false, E);
61196128
return false;
61206129
}
61216130

clang/lib/AST/ByteCode/Interp.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,14 +1944,14 @@ inline bool CastMemberPtrPtr(InterpState &S, CodePtr OpPC) {
19441944

19451945
template <class T, ArithOp Op>
19461946
bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
1947-
const Pointer &Ptr) {
1947+
const Pointer &Ptr, bool IsPointerArith = false) {
19481948
// A zero offset does not change the pointer.
19491949
if (Offset.isZero()) {
19501950
S.Stk.push<Pointer>(Ptr);
19511951
return true;
19521952
}
19531953

1954-
if (!CheckNull(S, OpPC, Ptr, CSK_ArrayIndex)) {
1954+
if (IsPointerArith && !CheckNull(S, OpPC, Ptr, CSK_ArrayIndex)) {
19551955
// The CheckNull will have emitted a note already, but we only
19561956
// abort in C++, since this is fine in C.
19571957
if (S.getLangOpts().CPlusPlus)
@@ -2063,14 +2063,16 @@ bool AddOffset(InterpState &S, CodePtr OpPC) {
20632063
Pointer Ptr = S.Stk.pop<Pointer>();
20642064
if (Ptr.isBlockPointer())
20652065
Ptr = Ptr.expand();
2066-
return OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr);
2066+
return OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr,
2067+
/*IsPointerArith=*/true);
20672068
}
20682069

20692070
template <PrimType Name, class T = typename PrimConv<Name>::T>
20702071
bool SubOffset(InterpState &S, CodePtr OpPC) {
20712072
const T &Offset = S.Stk.pop<T>();
20722073
const Pointer &Ptr = S.Stk.pop<Pointer>();
2073-
return OffsetHelper<T, ArithOp::Sub>(S, OpPC, Offset, Ptr);
2074+
return OffsetHelper<T, ArithOp::Sub>(S, OpPC, Offset, Ptr,
2075+
/*IsPointerArith=*/true);
20742076
}
20752077

20762078
template <ArithOp Op>
@@ -2090,7 +2092,7 @@ static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC,
20902092

20912093
// Now the current Ptr again and a constant 1.
20922094
OneT One = OneT::from(1);
2093-
if (!OffsetHelper<OneT, Op>(S, OpPC, One, P))
2095+
if (!OffsetHelper<OneT, Op>(S, OpPC, One, P, /*IsPointerArith=*/true))
20942096
return false;
20952097

20962098
// Store the new value.
@@ -2816,9 +2818,18 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
28162818
return false;
28172819
}
28182820

2819-
inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC,
2820-
const DeclRefExpr *DR) {
2821+
inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR,
2822+
bool InitializerFailed) {
28212823
assert(DR);
2824+
2825+
if (InitializerFailed) {
2826+
const SourceInfo &Loc = S.Current->getSource(OpPC);
2827+
const auto *VD = cast<VarDecl>(DR->getDecl());
2828+
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
2829+
S.Note(VD->getLocation(), diag::note_declared_at);
2830+
return false;
2831+
}
2832+
28222833
return CheckDeclRef(S, OpPC, DR);
28232834
}
28242835

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,10 @@ static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
12531253
const InterpFrame *Frame,
12541254
const Function *Func,
12551255
const CallExpr *Call) {
1256+
if (!Call->getArg(0)->getType()->isIntegerType() ||
1257+
!Call->getArg(1)->getType()->isIntegerType())
1258+
return false;
1259+
12561260
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
12571261
PrimType IndexT = *S.Ctx.classify(Call->getArg(1));
12581262
APSInt Val = peekToAPSInt(S.Stk, ValT,
@@ -1331,6 +1335,10 @@ static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
13311335
const InterpFrame *Frame,
13321336
const Function *Func,
13331337
const CallExpr *Call) {
1338+
if (!Call->getArg(0)->getType()->isIntegerType() ||
1339+
!Call->getArg(1)->getType()->isIntegerType())
1340+
return false;
1341+
13341342
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
13351343
PrimType MaskT = *S.Ctx.classify(Call->getArg(1));
13361344

@@ -1352,6 +1360,10 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
13521360
const InterpFrame *Frame,
13531361
const Function *Func,
13541362
const CallExpr *Call) {
1363+
if (!Call->getArg(0)->getType()->isIntegerType() ||
1364+
!Call->getArg(1)->getType()->isIntegerType())
1365+
return false;
1366+
13551367
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
13561368
PrimType MaskT = *S.Ctx.classify(Call->getArg(1));
13571369

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def InvalidCast : Opcode {
769769
}
770770

771771
def InvalidDeclRef : Opcode {
772-
let Args = [ArgDeclRef];
772+
let Args = [ArgDeclRef, ArgBool];
773773
}
774774

775775
def SizelessVectorElementSize : Opcode;

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
635635

636636
// Return the composite type.
637637
APValue Result;
638-
if (!Composite(getType(), *this, Result))
638+
if (!Composite(ResultType, *this, Result))
639639
return std::nullopt;
640640
return Result;
641641
}

clang/lib/AST/ExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ bool CXXTypeidExpr::isPotentiallyEvaluated() const {
147147
return false;
148148
}
149149

150-
bool CXXTypeidExpr::isMostDerived(ASTContext &Context) const {
150+
bool CXXTypeidExpr::isMostDerived(const ASTContext &Context) const {
151151
assert(!isTypeOperand() && "Cannot call isMostDerived for typeid(type)");
152152
const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Context);
153153
if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -159,7 +159,7 @@ bool CXXTypeidExpr::isMostDerived(ASTContext &Context) const {
159159
return false;
160160
}
161161

162-
QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
162+
QualType CXXTypeidExpr::getTypeOperand(const ASTContext &Context) const {
163163
assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
164164
Qualifiers Quals;
165165
return Context.getUnqualifiedArrayType(

clang/lib/Basic/TargetInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
7070
HasStrictFP = false;
7171
PointerWidth = PointerAlign = 32;
7272
BoolWidth = BoolAlign = 8;
73+
ShortWidth = ShortAlign = 16;
7374
IntWidth = IntAlign = 32;
7475
LongWidth = LongAlign = 32;
7576
LongLongWidth = LongLongAlign = 64;
@@ -437,6 +438,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
437438
// what these normally are for the target.
438439
// We also define long long and long double here, although the
439440
// OpenCL standard only mentions these as "reserved".
441+
ShortWidth = ShortAlign = 16;
440442
IntWidth = IntAlign = 32;
441443
LongWidth = LongAlign = 64;
442444
LongLongWidth = LongLongAlign = 128;

0 commit comments

Comments
 (0)