Skip to content

Commit f16b215

Browse files
authored
merge main into amd-staging (llvm#1827)
2 parents 0a0686f + 049494e commit f16b215

File tree

183 files changed

+2738
-1573
lines changed

Some content is hidden

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

183 files changed

+2738
-1573
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/Basic/Targets/SPIR.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ static const unsigned SPIRDefIsPrivMap[] = {
5858
// Used by both the SPIR and SPIR-V targets.
5959
static const unsigned SPIRDefIsGenMap[] = {
6060
4, // Default
61-
// OpenCL address space values for this map are dummy and they can't be used
62-
0, // opencl_global
61+
// Some OpenCL address space values for this map are dummy and they can't be
62+
// used
63+
1, // opencl_global
6364
0, // opencl_local
6465
0, // opencl_constant
6566
0, // opencl_private

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,32 +2085,31 @@ bool SemaOpenACC::CheckDeclareClause(SemaOpenACC::OpenACCParsedClause &Clause,
20852085
}
20862086
} else {
20872087
const auto *DRE = cast<DeclRefExpr>(VarExpr);
2088-
const VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl());
2089-
if (Var)
2088+
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
20902089
CurDecl = Var->getCanonicalDecl();
20912090

2092-
// OpenACC3.3 2.13:
2093-
// A 'declare' directive must be in the same scope as the declaration of
2094-
// any var that appears in the clauses of the directive or any scope
2095-
// within a C/C++ function.
2096-
// We can't really check 'scope' here, so we check declaration context,
2097-
// which is a reasonable approximation, but misses scopes inside of
2098-
// functions.
2099-
if (removeLinkageSpecDC(Var->getCanonicalDecl()
2100-
->getLexicalDeclContext()
2101-
->getPrimaryContext()) != DC) {
2102-
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2103-
<< Clause.getClauseKind();
2104-
continue;
2105-
}
2106-
// OpenACC3.3 2.13:
2107-
// C and C++ extern variables may only appear in 'create',
2108-
// 'copyin', 'deviceptr', 'device_resident', or 'link' clauses on a
2109-
// 'declare' directive.
2110-
if (!IsSpecialClause && Var && Var->hasExternalStorage()) {
2111-
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_extern)
2112-
<< Clause.getClauseKind();
2113-
continue;
2091+
// OpenACC3.3 2.13:
2092+
// A 'declare' directive must be in the same scope as the declaration of
2093+
// any var that appears in the clauses of the directive or any scope
2094+
// within a C/C++ function.
2095+
// We can't really check 'scope' here, so we check declaration context,
2096+
// which is a reasonable approximation, but misses scopes inside of
2097+
// functions.
2098+
if (removeLinkageSpecDC(
2099+
Var->getLexicalDeclContext()->getPrimaryContext()) != DC) {
2100+
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2101+
<< Clause.getClauseKind();
2102+
continue;
2103+
}
2104+
// OpenACC3.3 2.13:
2105+
// C and C++ extern variables may only appear in 'create',
2106+
// 'copyin', 'deviceptr', 'device_resident', or 'link' clauses on a
2107+
// 'declare' directive.
2108+
if (!IsSpecialClause && Var->hasExternalStorage()) {
2109+
Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_extern)
2110+
<< Clause.getClauseKind();
2111+
continue;
2112+
}
21142113
}
21152114

21162115
// OpenACC3.3 2.13:

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/CodeGenCUDASPIRV/printf.cu

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -fcuda-is-device -triple spirv32 -o - -emit-llvm -x cuda %s | FileCheck --check-prefix=CHECK-SPIRV32 %s
2+
// RUN: %clang_cc1 -fcuda-is-device -triple spirv64 -o - -emit-llvm -x cuda %s | FileCheck --check-prefix=CHECK-SPIRV64 %s
3+
4+
// CHECK-SPIRV32: @.str = private unnamed_addr addrspace(4) constant [13 x i8] c"Hello World\0A\00", align 1
5+
// CHECK-SPIRV64: @.str = private unnamed_addr addrspace(1) constant [13 x i8] c"Hello World\0A\00", align 1
6+
7+
extern "C" __attribute__((device)) int printf(const char* format, ...);
8+
9+
__attribute__((global)) void printf_kernel() {
10+
printf("Hello World\n");
11+
}

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.

libc/test/src/math/performance_testing/BinaryOpSingleOutputPerf.h

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)