Skip to content

Commit ad12bef

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:4e6e476329a8 into amd-gfx:5512cfecfe63
Local branch amd-gfx 5512cfe Merged main:34ee53c9e390 into amd-gfx:85bfd92dd479 Remote branch main 4e6e476 [MemCpyOpt] Merge alias metadatas when replacing arguments (llvm#67539)
2 parents 5512cfe + 4e6e476 commit ad12bef

File tree

48 files changed

+869
-145
lines changed

Some content is hidden

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

48 files changed

+869
-145
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install clang-format
2828
uses: aminya/setup-cpp@v1
2929
with:
30-
clangformat: 16.0.6
30+
clangformat: 17.0.1
3131

3232
- name: Setup Python env
3333
uses: actions/setup-python@v4

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ Bug Fixes to C++ Support
359359
reference. Fixes:
360360
(`#64162 <https://github.com/llvm/llvm-project/issues/64162>`_)
361361

362+
- Clang no longer tries to capture non-odr-used variables that appear
363+
in the enclosing expression of a lambda expression with a noexcept specifier.
364+
(`#67492 <https://github.com/llvm/llvm-project/issues/67492>`_)
365+
362366
Bug Fixes to AST Handling
363367
^^^^^^^^^^^^^^^^^^^^^^^^^
364368
- Fixed an import failure of recursive friend class template.

clang/include/clang/Basic/Module.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ class alignas(8) Module {
587587
return Kind == ModuleInterfaceUnit || isModulePartition();
588588
}
589589

590+
/// Is this a C++20 named module unit.
591+
bool isNamedModuleUnit() const {
592+
return isInterfaceOrPartition() || isModuleImplementation();
593+
}
594+
590595
bool isModuleInterfaceUnit() const {
591596
return Kind == ModuleInterfaceUnit || Kind == ModulePartitionInterface;
592597
}
@@ -720,13 +725,13 @@ class alignas(8) Module {
720725
/// one.
721726
///
722727
/// \returns The GMF sub-module if found, or NULL otherwise.
723-
Module *getGlobalModuleFragment() { return findSubmodule("<global>"); }
728+
Module *getGlobalModuleFragment() const;
724729

725730
/// Get the Private Module Fragment (sub-module) for this module, it there is
726731
/// one.
727732
///
728733
/// \returns The PMF sub-module if found, or NULL otherwise.
729-
Module *getPrivateModuleFragment() { return findSubmodule("<private>"); }
734+
Module *getPrivateModuleFragment() const;
730735

731736
/// Determine whether the specified module would be visible to
732737
/// a lookup at the end of this module.

clang/lib/Basic/Module.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,28 @@ Module *Module::findOrInferSubmodule(StringRef Name) {
370370
return Result;
371371
}
372372

373+
Module *Module::getGlobalModuleFragment() const {
374+
assert(isNamedModuleUnit() && "We should only query the global module "
375+
"fragment from the C++ 20 Named modules");
376+
377+
for (auto *SubModule : SubModules)
378+
if (SubModule->isExplicitGlobalModule())
379+
return SubModule;
380+
381+
return nullptr;
382+
}
383+
384+
Module *Module::getPrivateModuleFragment() const {
385+
assert(isNamedModuleUnit() && "We should only query the private module "
386+
"fragment from the C++ 20 Named modules");
387+
388+
for (auto *SubModule : SubModules)
389+
if (SubModule->isPrivateModule())
390+
return SubModule;
391+
392+
return nullptr;
393+
}
394+
373395
void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const {
374396
// All non-explicit submodules are exported.
375397
for (std::vector<Module *>::const_iterator I = SubModules.begin(),

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,9 @@ static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod,
29152915
}
29162916

29172917
void CodeGenModule::EmitModuleInitializers(clang::Module *Primary) {
2918+
assert(Primary->isNamedModuleUnit() &&
2919+
"We should only emit module initializers for named modules.");
2920+
29182921
// Emit the initializers in the order that sub-modules appear in the
29192922
// source, first Global Module Fragments, if present.
29202923
if (auto GMF = Primary->getGlobalModuleFragment()) {

clang/lib/Driver/ToolChain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,8 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
13191319
if (getTriple().getArch() == llvm::Triple::x86 ||
13201320
getTriple().getArch() == llvm::Triple::x86_64 ||
13211321
getTriple().getArch() == llvm::Triple::arm || getTriple().isWasm() ||
1322-
getTriple().isAArch64() || getTriple().isRISCV())
1322+
getTriple().isAArch64() || getTriple().isRISCV() ||
1323+
getTriple().isLoongArch64())
13231324
Res |= SanitizerKind::CFIICall;
13241325
if (getTriple().getArch() == llvm::Triple::x86_64 ||
13251326
getTriple().isAArch64(64) || getTriple().isRISCV())

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,11 @@ void Parser::ParseDeclarationSpecifiers(
41204120
ExprResult ExplicitExpr(static_cast<Expr *>(nullptr));
41214121
BalancedDelimiterTracker Tracker(*this, tok::l_paren);
41224122
Tracker.consumeOpen();
4123-
ExplicitExpr = ParseConstantExpression();
4123+
4124+
EnterExpressionEvaluationContext ConstantEvaluated(
4125+
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4126+
4127+
ExplicitExpr = ParseConstantExpressionInExprEvalContext();
41244128
ConsumedEnd = Tok.getLocation();
41254129
if (ExplicitExpr.isUsable()) {
41264130
CloseParenLoc = Tok.getLocation();

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3983,7 +3983,11 @@ ExceptionSpecificationType Parser::tryParseExceptionSpecification(
39833983
// There is an argument.
39843984
BalancedDelimiterTracker T(*this, tok::l_paren);
39853985
T.consumeOpen();
3986-
NoexceptExpr = ParseConstantExpression();
3986+
3987+
EnterExpressionEvaluationContext ConstantEvaluated(
3988+
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
3989+
NoexceptExpr = ParseConstantExpressionInExprEvalContext();
3990+
39873991
T.consumeClose();
39883992
if (!NoexceptExpr.isInvalid()) {
39893993
NoexceptExpr =

clang/test/Driver/fsanitize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@
600600
// RUN: %clang --target=aarch64_be -fvisibility=hidden -fsanitize=cfi -flto -resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
601601
// RUN: %clang --target=riscv32 -fvisibility=hidden -fsanitize=cfi -flto -resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
602602
// RUN: %clang --target=riscv64 -fvisibility=hidden -fsanitize=cfi -flto -resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
603+
// RUN: %clang --target=loongarch64 -fvisibility=hidden -fsanitize=cfi -flto -resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI
603604
// CHECK-CFI: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
604605
// CHECK-CFI-NOMFCALL: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
605606
// CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,8 @@ void foo() {
718718
void GH48527() {
719719
auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}}
720720
}
721+
722+
void GH67492() {
723+
constexpr auto test = 42;
724+
auto lambda = (test, []() noexcept(true) {});
725+
}

compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
7373
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64}
7474
${HEXAGON} ${LOONGARCH64})
7575
set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}
76-
${HEXAGON})
76+
${HEXAGON} ${LOONGARCH64})
7777
set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
7878
${MIPS32} ${MIPS64} ${PPC64} ${HEXAGON} ${LOONGARCH64} ${RISCV64})
7979
if(APPLE)

compiler-rt/lib/cfi/cfi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ using namespace __sanitizer;
5151

5252
namespace __cfi {
5353

54+
#if SANITIZER_LOONGARCH64
55+
#define kCfiShadowLimitsStorageSize 16384 // 16KiB on loongarch64 per page
56+
#else
5457
#define kCfiShadowLimitsStorageSize 4096 // 1 page
58+
#endif
5559
// Lets hope that the data segment is mapped with 4K pages.
5660
// The pointer to the cfi shadow region is stored at the start of this page.
5761
// The rest of the page is unused and re-mapped read-only.

compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ struct A {
5353
virtual void f();
5454
};
5555

56+
// The page size of LoongArch is 16KiB, aligned to the memory page size.
57+
#ifdef __loongarch__
58+
# define PAGESIZE 16384
59+
#else
60+
# define PAGESIZE 4096
61+
#endif
62+
5663
#ifdef SHARED_LIB
5764

5865
#include "../../utils.h"
@@ -66,13 +73,13 @@ extern "C" void *create_B() {
6673
return (void *)(new B());
6774
}
6875

69-
extern "C" __attribute__((aligned(4096))) void do_nothing() {}
76+
extern "C" __attribute__((aligned(PAGESIZE))) void do_nothing() {}
7077

7178
#else
7279

7380
void A::f() {}
7481

75-
static const int kCodeAlign = 4096;
82+
static const int kCodeAlign = PAGESIZE;
7683
static const int kCodeSize = 4096;
7784
static char saved_code[kCodeSize];
7885
static char *real_start;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# The cfi-icall checker is only supported on x86 and x86_64 for now.
2-
if config.root.host_arch not in ["x86", "x86_64"]:
2+
if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
33
config.unsupported = True
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# The cfi-icall checker is only supported on x86 and x86_64 for now.
2-
if config.root.host_arch not in ["x86", "x86_64"]:
2+
if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
33
config.unsupported = True

flang/include/flang/Evaluate/call.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ template <typename A> class FunctionRef : public ProcedureRef {
268268
FunctionRef(ProcedureDesignator &&p, ActualArguments &&a)
269269
: ProcedureRef{std::move(p), std::move(a)} {}
270270

271-
std::optional<DynamicType> GetType() const { return proc_.GetType(); }
271+
std::optional<DynamicType> GetType() const {
272+
if (auto type{proc_.GetType()}) {
273+
// TODO: Non constant explicit length parameters of PDTs result should
274+
// likely be dropped too. This is not as easy as for characters since some
275+
// long lived DerivedTypeSpec pointer would need to be created here. It is
276+
// not clear if this is causing any issue so far since the storage size of
277+
// PDTs is independent of length parameters.
278+
return type->DropNonConstantCharacterLength();
279+
}
280+
return std::nullopt;
281+
}
272282
};
273283
} // namespace Fortran::evaluate
274284
#endif // FORTRAN_EVALUATE_CALL_H_

flang/include/flang/Evaluate/type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ class DynamicType {
231231
}
232232
}
233233

234+
// Get a copy of this dynamic type where charLengthParamValue_ is reset if it
235+
// is not a constant expression. This avoids propagating symbol references in
236+
// scopes where they do not belong. Returns the type unmodified if it is not
237+
// a character or if the length is not explicit.
238+
DynamicType DropNonConstantCharacterLength() const;
239+
234240
private:
235241
// Special kind codes are used to distinguish the following Fortran types.
236242
enum SpecialKind {

flang/lib/Evaluate/type.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,4 +836,15 @@ bool IsCUDAIntrinsicType(const DynamicType &type) {
836836
}
837837
}
838838

839+
DynamicType DynamicType::DropNonConstantCharacterLength() const {
840+
if (charLengthParamValue_ && charLengthParamValue_->isExplicit()) {
841+
if (std::optional<std::int64_t> len{knownLength()}) {
842+
return DynamicType(kind_, *len);
843+
} else {
844+
return DynamicType(category_, kind_);
845+
}
846+
}
847+
return *this;
848+
}
849+
839850
} // namespace Fortran::evaluate

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5284,11 +5284,8 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType,
52845284
builder.getKindMap().getIntegerBitsize(fir::toInt(constOp)));
52855285
}
52865286

5287-
if (args[0].getBoxOf<fir::PolymorphicValue>()) {
5288-
box = builder.createBox(loc, args[0], /*isPolymorphic=*/true);
5289-
} else if (box.getType().isa<fir::ReferenceType>()) {
5290-
box = builder.create<fir::LoadOp>(loc, box);
5291-
}
5287+
box = builder.createBox(loc, args[0],
5288+
/*isPolymorphic=*/args[0].isPolymorphic());
52925289
mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, kindTy, box);
52935290
mlir::Value c8 = builder.createIntegerConstant(loc, kindTy, 8);
52945291
return builder.create<mlir::arith::MulIOp>(loc, eleSize, c8);

flang/test/Evaluate/rewrite06.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
subroutine test_storage_size(n)
3+
interface
4+
function return_char(l)
5+
integer :: l
6+
character(l) :: return_char
7+
end function
8+
end interface
9+
integer n
10+
!CHECK: PRINT *, storage_size(return_char(n))
11+
print*, storage_size(return_char(n))
12+
!CHECK: PRINT *, sizeof(return_char(n))
13+
print*, sizeof(return_char(n))
14+
end subroutine
15+
16+
module pdts
17+
type t(l)
18+
integer, len :: l
19+
character(l) :: c
20+
end type
21+
contains
22+
function return_pdt(n)
23+
type(t(n)) :: return_pdt
24+
end function
25+
subroutine test(k)
26+
! NOTE: flang design for length parametrized derived type
27+
! is to use allocatables for the automatic components. Hence,
28+
! their size is independent from the length parameters and is
29+
! a compile time constant.
30+
!CHECK: PRINT *, 192_4
31+
print *, storage_size(return_pdt(k))
32+
end subroutine
33+
end module
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
! Test storage_size with characters
2+
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s
3+
4+
! check-label: func.func @_QPtest_storage_size
5+
subroutine test_storage_size(n)
6+
interface
7+
function return_char(l)
8+
integer :: l
9+
character(l) :: return_char
10+
end function
11+
end interface
12+
integer n
13+
print*, storage_size(return_char(n))
14+
! CHECK: %[[val_16:.*]] = fir.call @_QPreturn_char(%[[res_addr:[^,]*]], %[[res_len:[^,]*]], {{.*}})
15+
! CHECK: %[[res:.*]]:2 = hlfir.declare %[[res_addr]] typeparams %[[res_len]]
16+
! CHECK: %[[val_18:.*]] = fir.embox %[[res]]#1 typeparams %[[res_len]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.box<!fir.char<1,?>>
17+
! CHECK: %[[val_19:.*]] = fir.box_elesize %[[val_18]] : (!fir.box<!fir.char<1,?>>) -> i32
18+
! CHECK: %[[val_20:.*]] = arith.constant 8 : i32
19+
! CHECK: %[[val_21:.*]] = arith.muli %[[val_19]], %[[val_20]] : i32
20+
! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[val_21]])
21+
end subroutine
22+
23+
function return_char(l)
24+
integer :: l
25+
character(l) :: return_char
26+
end function
27+
28+
call test_storage_size(42)
29+
print *, 42*8
30+
end

flang/test/Semantics/call05.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ subroutine smb(b)
155155
integer, allocatable, intent(in) :: b(:)
156156
end
157157

158+
function return_deferred_length_ptr()
159+
character(len=:), pointer :: return_deferred_length_ptr
160+
end function
161+
162+
function return_explicit_length_ptr(n)
163+
integer :: n
164+
character(len=n), pointer :: return_explicit_length_ptr
165+
end function
166+
158167
subroutine test()
159168

160169
!ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
@@ -167,6 +176,16 @@ subroutine test()
167176

168177
call smp2(p1) ! ok
169178

179+
call smp(return_deferred_length_ptr()) ! ok
180+
181+
!ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
182+
call smp2(return_deferred_length_ptr())
183+
184+
!ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
185+
call smp(return_explicit_length_ptr(10))
186+
187+
call smp2(return_explicit_length_ptr(10)) ! ok
188+
170189
!ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
171190
call sma(t2(:))
172191

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 476172
19+
#define LLVM_MAIN_REVISION 476185
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

0 commit comments

Comments
 (0)