Skip to content

Commit 6b0cfc6

Browse files
committed
Merge from 'main' to 'sycl-web' (#49)
CONFLICT (content): Merge conflict in clang/test/Misc/nvptx.languageOptsOpenCL.cl
2 parents 0b9bd61 + 4fde2b6 commit 6b0cfc6

File tree

257 files changed

+6714
-1278
lines changed

Some content is hidden

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

257 files changed

+6714
-1278
lines changed

clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ TEST_F(TUSchedulerTests, CommandLineWarnings) {
10421042

10431043
TEST(DebouncePolicy, Compute) {
10441044
namespace c = std::chrono;
1045-
std::vector<DebouncePolicy::clock::duration> History = {
1045+
DebouncePolicy::clock::duration History[] = {
10461046
c::seconds(0),
10471047
c::seconds(5),
10481048
c::seconds(10),
@@ -1053,8 +1053,9 @@ TEST(DebouncePolicy, Compute) {
10531053
Policy.Max = c::seconds(25);
10541054
// Call Policy.compute(History) and return seconds as a float.
10551055
auto Compute = [&](llvm::ArrayRef<DebouncePolicy::clock::duration> History) {
1056-
using FloatingSeconds = c::duration<float, c::seconds::period>;
1057-
return static_cast<float>(Policy.compute(History) / FloatingSeconds(1));
1056+
return c::duration_cast<c::duration<float, c::seconds::period>>(
1057+
Policy.compute(History))
1058+
.count();
10581059
};
10591060
EXPECT_NEAR(10, Compute(History), 0.01) << "(upper) median = 10";
10601061
Policy.RebuildRatio = 1.5;

clang/docs/LanguageExtensions.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,58 @@ syntax to be used with ``std::complex`` with the same meaning.)
17221722
For GCC compatibility, ``__builtin_complex(re, im)`` can also be used to
17231723
construct a complex number from the given real and imaginary components.
17241724
1725+
OpenCL Features
1726+
===============
1727+
1728+
Clang supports internal OpenCL extensions documented below.
1729+
1730+
``__cl_clang_function_pointers``
1731+
--------------------------------
1732+
1733+
With this extension it is possible to enable various language features that
1734+
are relying on function pointers using regular OpenCL extension pragma
1735+
mechanism detailed in `the OpenCL Extension Specification,
1736+
section 1.2
1737+
<https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#extensions-overview>`_.
1738+
1739+
In C++ for OpenCL this also enables:
1740+
1741+
- Use of member function pointers;
1742+
1743+
- Unrestricted use of references to functions;
1744+
1745+
- Virtual member functions.
1746+
1747+
Such functionality is not conformant and does not guarantee to compile
1748+
correctly in any circumstances. It can be used if:
1749+
1750+
- the kernel source does not contain call expressions to (member-) function
1751+
pointers, or virtual functions. For example this extension can be used in
1752+
metaprogramming algorithms to be able to specify/detect types generically.
1753+
1754+
- the generated kernel binary does not contain indirect calls because they
1755+
are eliminated using compiler optimizations e.g. devirtualization.
1756+
1757+
- the selected target supports the function pointer like functionality e.g.
1758+
most CPU targets.
1759+
1760+
**Example of Use**:
1761+
1762+
.. code-block:: c++
1763+
1764+
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
1765+
void foo()
1766+
{
1767+
void (*fp)(); // compiled - no diagnostic generated
1768+
}
1769+
1770+
#pragma OPENCL EXTENSION __cl_clang_function_pointers : disable
1771+
void bar()
1772+
{
1773+
void (*fp)(); // error - pointers to function are not allowed
1774+
}
1775+
1776+
17251777
Builtin Functions
17261778
=================
17271779

clang/include/clang/Basic/OpenCLExtensions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
6969

7070
// Clang Extensions.
7171
OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)
72+
OPENCLEXT_INTERNAL(__cl_clang_function_pointers, 100, ~0U)
7273

7374
// AMD OpenCL extensions
7475
OPENCLEXT_INTERNAL(cl_amd_media_ops, 100, ~0U)

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def C : Flag<["-"], "C">, Flags<[CC1Option]>, Group<Preprocessor_Group>,
633633
HelpText<"Include comments in preprocessed output">,
634634
MarshallingInfoFlag<"PreprocessorOutputOpts.ShowComments">;
635635
def D : JoinedOrSeparate<["-"], "D">, Group<Preprocessor_Group>,
636-
Flags<[CC1Option]>, MetaVarName<"<macro>=<value>">,
636+
Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"<macro>=<value>">,
637637
HelpText<"Define <macro> to <value> (or 1 if <value> omitted)">;
638638
def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, FC1Option]>, Group<Action_Group>,
639639
HelpText<"Only run the preprocessor">;
@@ -732,7 +732,7 @@ def Ttext : JoinedOrSeparate<["-"], "Ttext">, Group<T_Group>,
732732
def T : JoinedOrSeparate<["-"], "T">, Group<T_Group>,
733733
MetaVarName<"<script>">, HelpText<"Specify <script> as linker script">;
734734
def U : JoinedOrSeparate<["-"], "U">, Group<Preprocessor_Group>,
735-
Flags<[CC1Option]>, MetaVarName<"<macro>">, HelpText<"Undefine macro <macro>">;
735+
Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"<macro>">, HelpText<"Undefine macro <macro>">;
736736
def V : JoinedOrSeparate<["-"], "V">, Flags<[NoXarchOption, Unsupported]>;
737737
def Wa_COMMA : CommaJoined<["-"], "Wa,">,
738738
HelpText<"Pass the comma separated arguments in <arg> to the assembler">,

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
285285
void setSupportedOpenCLOpts() override {
286286
auto &Opts = getSupportedOpenCLOpts();
287287
Opts.support("cl_clang_storage_class_specifiers");
288+
Opts.support("__cl_clang_function_pointers");
288289

289290
bool IsAMDGCN = isAMDGCN(getTriple());
290291

clang/lib/Basic/Targets/NVPTX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
128128
void setSupportedOpenCLOpts() override {
129129
auto &Opts = getSupportedOpenCLOpts();
130130
Opts.support("cl_clang_storage_class_specifiers");
131+
Opts.support("__cl_clang_function_pointers");
131132

132133
Opts.support("cl_khr_fp64");
133134
Opts.support("cl_khr_byte_addressable_store");

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,14 +3988,14 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
39883988
CmdArgs.push_back("-gno-inline-line-tables");
39893989
}
39903990

3991-
// Adjust the debug info kind for the given toolchain.
3992-
TC.adjustDebugInfoKind(DebugInfoKind, Args);
3993-
39943991
// When emitting remarks, we need at least debug lines in the output.
39953992
if (willEmitRemarks(Args) &&
39963993
DebugInfoKind <= codegenoptions::DebugDirectivesOnly)
39973994
DebugInfoKind = codegenoptions::DebugLineTablesOnly;
39983995

3996+
// Adjust the debug info kind for the given toolchain.
3997+
TC.adjustDebugInfoKind(DebugInfoKind, Args);
3998+
39993999
RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, EffectiveDWARFVersion,
40004000
DebuggerTuning);
40014001

@@ -6659,26 +6659,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66596659
options::OPT_fno_cxx_static_destructors, true))
66606660
CmdArgs.push_back("-fno-c++-static-destructors");
66616661

6662-
if (Arg *A = Args.getLastArg(options::OPT_moutline,
6663-
options::OPT_mno_outline)) {
6664-
if (A->getOption().matches(options::OPT_moutline)) {
6665-
// We only support -moutline in AArch64 and ARM targets right now. If
6666-
// we're not compiling for these, emit a warning and ignore the flag.
6667-
// Otherwise, add the proper mllvm flags.
6668-
if (!(Triple.isARM() || Triple.isThumb() ||
6669-
Triple.getArch() == llvm::Triple::aarch64 ||
6670-
Triple.getArch() == llvm::Triple::aarch64_32)) {
6671-
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
6672-
} else {
6673-
CmdArgs.push_back("-mllvm");
6674-
CmdArgs.push_back("-enable-machine-outliner");
6675-
}
6676-
} else {
6677-
// Disable all outlining behaviour.
6678-
CmdArgs.push_back("-mllvm");
6679-
CmdArgs.push_back("-enable-machine-outliner=never");
6680-
}
6681-
}
6662+
addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);
66826663

66836664
if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
66846665
options::OPT_mno_outline_atomics)) {

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
632632

633633
// Handle remarks hotness/threshold related options.
634634
renderRemarksHotnessOptions(Args, CmdArgs);
635+
636+
addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(),
637+
/*IsLTO=*/true);
635638
}
636639

637640
void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
@@ -1594,3 +1597,36 @@ unsigned tools::getOrCheckAMDGPUCodeObjectVersion(
15941597
}
15951598
return CodeObjVer;
15961599
}
1600+
1601+
void tools::addMachineOutlinerArgs(const Driver &D,
1602+
const llvm::opt::ArgList &Args,
1603+
llvm::opt::ArgStringList &CmdArgs,
1604+
const llvm::Triple &Triple, bool IsLTO) {
1605+
auto addArg = [&, IsLTO](const Twine &Arg) {
1606+
if (IsLTO) {
1607+
CmdArgs.push_back(Args.MakeArgString("-plugin-opt=" + Arg));
1608+
} else {
1609+
CmdArgs.push_back("-mllvm");
1610+
CmdArgs.push_back(Args.MakeArgString(Arg));
1611+
}
1612+
};
1613+
1614+
if (Arg *A = Args.getLastArg(options::OPT_moutline,
1615+
options::OPT_mno_outline)) {
1616+
if (A->getOption().matches(options::OPT_moutline)) {
1617+
// We only support -moutline in AArch64 and ARM targets right now. If
1618+
// we're not compiling for these, emit a warning and ignore the flag.
1619+
// Otherwise, add the proper mllvm flags.
1620+
if (!(Triple.isARM() || Triple.isThumb() ||
1621+
Triple.getArch() == llvm::Triple::aarch64 ||
1622+
Triple.getArch() == llvm::Triple::aarch64_32)) {
1623+
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
1624+
} else {
1625+
addArg(Twine("-enable-machine-outliner"));
1626+
}
1627+
} else {
1628+
// Disable all outlining behaviour.
1629+
addArg(Twine("-enable-machine-outliner=never"));
1630+
}
1631+
}
1632+
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
141141
unsigned getOrCheckAMDGPUCodeObjectVersion(const Driver &D,
142142
const llvm::opt::ArgList &Args,
143143
bool Diagnose = false);
144+
145+
void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
146+
llvm::opt::ArgStringList &CmdArgs,
147+
const llvm::Triple &Triple, bool IsLTO);
144148
} // end namespace tools
145149
} // end namespace driver
146150
} // end namespace clang

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args) {
384384
}
385385
return IsDebugEnabled ? EmitSameDebugInfoAsHost : DebugDirectivesOnly;
386386
}
387-
return DisableDebugInfo;
387+
return willEmitRemarks(Args) ? DebugDirectivesOnly : DisableDebugInfo;
388388
}
389389

390390
void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ using namespace clang::driver::tools;
1919
using namespace clang;
2020
using namespace llvm::opt;
2121

22+
void Flang::AddPreprocessingOptions(const ArgList &Args,
23+
ArgStringList &CmdArgs) const {
24+
Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U});
25+
}
26+
2227
void Flang::ConstructJob(Compilation &C, const JobAction &JA,
2328
const InputInfo &Output, const InputInfoList &Inputs,
2429
const ArgList &Args, const char *LinkingOutput) const {
@@ -63,14 +68,21 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
6368
assert(false && "Unexpected action class for Flang tool.");
6469
}
6570

71+
const InputInfo &Input = Inputs[0];
72+
types::ID InputType = Input.getType();
73+
74+
// Add preprocessing options like -I, -D, etc. if we are using the
75+
// preprocessor (i.e. skip when dealing with e.g. binary files).
76+
if (types::getPreprocessedType(InputType) != types::TY_INVALID)
77+
AddPreprocessingOptions(Args, CmdArgs);
78+
6679
if (Output.isFilename()) {
6780
CmdArgs.push_back("-o");
6881
CmdArgs.push_back(Output.getFilename());
6982
} else {
7083
assert(Output.isNothing() && "Invalid output.");
7184
}
7285

73-
const InputInfo &Input = Inputs[0];
7486
assert(Input.isFilename() && "Invalid input.");
7587
CmdArgs.push_back(Input.getFilename());
7688

clang/lib/Driver/ToolChains/Flang.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ namespace tools {
2323

2424
/// Flang compiler tool.
2525
class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
26+
private:
27+
/// Extract preprocessing options from the driver arguments and add them to
28+
/// the preprocessor command arguments.
29+
///
30+
/// \param [in] Args The list of input driver arguments
31+
/// \param [out] CmdArgs The list of output command arguments
32+
void AddPreprocessingOptions(const llvm::opt::ArgList &Args,
33+
llvm::opt::ArgStringList &CmdArgs) const;
34+
2635
public:
2736
Flang(const ToolChain &TC);
2837
~Flang() override;

clang/lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,12 +3631,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
36313631
case tok::kw_virtual:
36323632
// C++ for OpenCL does not allow virtual function qualifier, to avoid
36333633
// function pointers restricted in OpenCL v2.0 s6.9.a.
3634-
if (getLangOpts().OpenCLCPlusPlus) {
3634+
if (getLangOpts().OpenCLCPlusPlus &&
3635+
!getActions().getOpenCLOptions().isEnabled(
3636+
"__cl_clang_function_pointers")) {
36353637
DiagID = diag::err_openclcxx_virtual_function;
36363638
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
36373639
isInvalid = true;
3638-
}
3639-
else {
3640+
} else {
36403641
isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
36413642
}
36423643
break;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6776,14 +6776,16 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema &Se, Declarator &D,
67766776
}
67776777

67786778
// OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
6779-
QualType NR = R;
6780-
while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
6781-
if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
6782-
Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
6783-
D.setInvalidType();
6784-
return false;
6779+
if (!Se.getOpenCLOptions().isEnabled("__cl_clang_function_pointers")) {
6780+
QualType NR = R;
6781+
while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
6782+
if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
6783+
Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
6784+
D.setInvalidType();
6785+
return false;
6786+
}
6787+
NR = NR->getPointeeType();
67856788
}
6786-
NR = NR->getPointeeType();
67876789
}
67886790

67896791
if (!Se.getOpenCLOptions().isEnabled("cl_khr_fp16")) {

clang/lib/Sema/SemaInit.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8201,9 +8201,21 @@ ExprResult InitializationSequence::Perform(Sema &S,
82018201
if (S.CheckExceptionSpecCompatibility(CurInit.get(), DestType))
82028202
return ExprError();
82038203

8204+
QualType MTETy = Step->Type;
8205+
8206+
// When this is an incomplete array type (such as when this is
8207+
// initializing an array of unknown bounds from an init list), use THAT
8208+
// type instead so that we propogate the array bounds.
8209+
if (MTETy->isIncompleteArrayType() &&
8210+
!CurInit.get()->getType()->isIncompleteArrayType() &&
8211+
S.Context.hasSameType(
8212+
MTETy->getPointeeOrArrayElementType(),
8213+
CurInit.get()->getType()->getPointeeOrArrayElementType()))
8214+
MTETy = CurInit.get()->getType();
8215+
82048216
// Materialize the temporary into memory.
82058217
MaterializeTemporaryExpr *MTE = S.CreateMaterializeTemporaryExpr(
8206-
Step->Type, CurInit.get(), Entity.getType()->isLValueReferenceType());
8218+
MTETy, CurInit.get(), Entity.getType()->isLValueReferenceType());
82078219
CurInit = MTE;
82088220

82098221
// If we're extending this temporary to automatic storage duration -- we

0 commit comments

Comments
 (0)