Skip to content

Commit 888a01d

Browse files
authored
Merge branch 'main' into Ziccamoc
2 parents 576161b + 72b2d4d commit 888a01d

File tree

101 files changed

+1106
-487
lines changed

Some content is hidden

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

101 files changed

+1106
-487
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,19 @@ inline bool CmpHelper<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
10071007
return false;
10081008
}
10091009

1010+
// Diagnose comparisons between fields with different access specifiers.
1011+
if (std::optional<std::pair<Pointer, Pointer>> Split =
1012+
Pointer::computeSplitPoint(LHS, RHS)) {
1013+
const FieldDecl *LF = Split->first.getField();
1014+
const FieldDecl *RF = Split->second.getField();
1015+
if (LF && RF && !LF->getParent()->isUnion() &&
1016+
LF->getAccess() != RF->getAccess()) {
1017+
S.CCEDiag(S.Current->getSource(OpPC),
1018+
diag::note_constexpr_pointer_comparison_differing_access)
1019+
<< LF << LF->getAccess() << RF << RF->getAccess() << LF->getParent();
1020+
}
1021+
}
1022+
10101023
unsigned VL = LHS.getByteOffset();
10111024
unsigned VR = RHS.getByteOffset();
10121025
S.Stk.push<BoolT>(BoolT::from(Fn(Compare(VL, VR))));

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,48 @@ bool Pointer::pointsToLiteral() const {
571571
return E && !isa<MaterializeTemporaryExpr, StringLiteral>(E);
572572
}
573573

574+
std::optional<std::pair<Pointer, Pointer>>
575+
Pointer::computeSplitPoint(const Pointer &A, const Pointer &B) {
576+
if (!A.isBlockPointer() || !B.isBlockPointer())
577+
return std::nullopt;
578+
579+
if (A.asBlockPointer().Pointee != B.asBlockPointer().Pointee)
580+
return std::nullopt;
581+
if (A.isRoot() && B.isRoot())
582+
return std::nullopt;
583+
584+
if (A == B)
585+
return std::make_pair(A, B);
586+
587+
auto getBase = [](const Pointer &P) -> Pointer {
588+
if (P.isArrayElement())
589+
return P.expand().getArray();
590+
return P.getBase();
591+
};
592+
593+
Pointer IterA = A;
594+
Pointer IterB = B;
595+
Pointer CurA = IterA;
596+
Pointer CurB = IterB;
597+
for (;;) {
598+
if (IterA.asBlockPointer().Base > IterB.asBlockPointer().Base) {
599+
CurA = IterA;
600+
IterA = getBase(IterA);
601+
} else {
602+
CurB = IterB;
603+
IterB = getBase(IterB);
604+
}
605+
606+
if (IterA == IterB)
607+
return std::make_pair(CurA, CurB);
608+
609+
if (IterA.isRoot() && IterB.isRoot())
610+
return std::nullopt;
611+
}
612+
613+
llvm_unreachable("The loop above should've returned.");
614+
}
615+
574616
std::optional<APValue> Pointer::toRValue(const Context &Ctx,
575617
QualType ResultType) const {
576618
const ASTContext &ASTCtx = Ctx.getASTContext();

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ class Pointer {
492492
return ElemDesc ? ElemDesc->ElemRecord : nullptr;
493493
}
494494
/// Returns the field information.
495-
const FieldDecl *getField() const { return getFieldDesc()->asFieldDecl(); }
495+
const FieldDecl *getField() const {
496+
if (const Descriptor *FD = getFieldDesc())
497+
return FD->asFieldDecl();
498+
return nullptr;
499+
}
496500

497501
/// Checks if the storage is extern.
498502
bool isExtern() const {
@@ -724,6 +728,9 @@ class Pointer {
724728
/// Checks if both given pointers point to the same block.
725729
static bool pointToSameBlock(const Pointer &A, const Pointer &B);
726730

731+
static std::optional<std::pair<Pointer, Pointer>>
732+
computeSplitPoint(const Pointer &A, const Pointer &B);
733+
727734
/// Whether this points to a block that's been created for a "literal lvalue",
728735
/// i.e. a non-MaterializeTemporaryExpr Expr.
729736
bool pointsToLiteral() const;

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9202,7 +9202,10 @@ bool LValueExprEvaluator::VisitExtVectorElementExpr(
92029202

92039203
if (Success) {
92049204
Result.setFrom(Info.Ctx, Val);
9205-
const auto *VT = E->getBase()->getType()->castAs<VectorType>();
9205+
QualType BaseType = E->getBase()->getType();
9206+
if (E->isArrow())
9207+
BaseType = BaseType->getPointeeType();
9208+
const auto *VT = BaseType->castAs<VectorType>();
92069209
HandleLValueVectorElement(Info, E, Result, VT->getElementType(),
92079210
VT->getNumElements(), Indices[0]);
92089211
}

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5980,7 +5980,7 @@ bool ASTReader::readASTFileControlBlock(
59805980
}
59815981
}
59825982
}
5983-
Stream = SavedStream;
5983+
Stream = std::move(SavedStream);
59845984
}
59855985

59865986
// Scan for the UNHASHED_CONTROL_BLOCK_ID block.

clang/test/AST/ByteCode/records.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,3 +1787,26 @@ namespace IntegralBaseCast {
17871787

17881788
static_assert(f() == 0, "");
17891789
}
1790+
1791+
namespace AccessMismatch {
1792+
struct A {
1793+
public:
1794+
constexpr A() : a(0), b(0) {}
1795+
int a;
1796+
constexpr bool cmp() const { return &a < &b; } // both-note {{comparison of address of fields 'a' and 'b' of 'A' with differing access specifiers (public vs private) has unspecified value}}
1797+
private:
1798+
int b;
1799+
};
1800+
static_assert(A().cmp(), ""); // both-error {{constant expression}} \
1801+
// both-note {{in call}}
1802+
1803+
class B {
1804+
public:
1805+
A a;
1806+
constexpr bool cmp() const { return &a.a < &b.a; } // both-note {{comparison of address of fields 'a' and 'b' of 'B' with differing access specifiers (public vs protected) has unspecified value}}
1807+
protected:
1808+
A b;
1809+
};
1810+
static_assert(B().cmp(), ""); // both-error {{constant expression}} \
1811+
// both-note {{in call}}
1812+
}

clang/test/CodeGenCXX/mangle-template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ namespace unresolved_template_specialization_type {
414414
AbslHashValue() {}
415415
};
416416
template enable_if<true> raw_hash_set<int>::AbslHashValue<HashStateBase>();
417-
// CHECH: @_ZN39unresolved_template_specialization_type12raw_hash_setIiE13AbslHashValueINS_13HashStateBaseEEENS_9enable_ifIXsrNT_11is_hashableIiEE5valueEEEv
417+
// CHECK: @_ZN39unresolved_template_specialization_type12raw_hash_setIiE13AbslHashValueINS_13HashStateBaseEEENS_9enable_ifIXsrNT_11is_hashableIiEE5valueEEEv
418418
} // namespace unresolved_template_specialization_type
419419

420420
namespace GH133610 {

clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ static_assert(b.lo.lo == 1); // expected-error {{not an integral constant expres
4343
// make sure clang rejects taking address of a vector element
4444
static_assert(&b[1]); // expected-error {{address of vector element requested}}
4545

46+
constexpr const FourIntsExtVec *p = &b;
47+
static_assert(p->x == 1);
4648
}

flang/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
452452
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-semantic-interposition")
453453
endif()
454454

455+
# GCC requires this flag in order for precompiled headers to work with ccache
456+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
457+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess")
458+
endif()
455459
endif()
456460

457461
# Clang on Darwin enables non-POSIX extensions by default, which allows the
@@ -462,6 +466,11 @@ if (APPLE)
462466
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809")
463467
endif()
464468

469+
# Clang requires this flag in order for precompiled headers to work with ccache
470+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
471+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp")
472+
endif()
473+
465474
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
466475

467476
# Determine HOST_LINK_VERSION on Darwin.

llvm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ if(LLVM_CCACHE_BUILD)
273273
if(CCACHE_PROGRAM)
274274
set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
275275
set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
276-
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
276+
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros"
277277
CACHE STRING "Parameters to pass through to ccache")
278278

279279
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
@@ -287,7 +287,7 @@ if(LLVM_CCACHE_BUILD)
287287
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
288288
else()
289289
if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
290-
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
290+
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros")
291291
message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
292292
endif()
293293
# RULE_LAUNCH_COMPILE should work with Ninja but currently has issues

0 commit comments

Comments
 (0)