Skip to content

Commit 21f3f75

Browse files
committed
Merge from 'main' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in clang/test/Misc/nvptx.languageOptsOpenCL.cl
2 parents bdac370 + 237c692 commit 21f3f75

File tree

191 files changed

+4475
-1282
lines changed

Some content is hidden

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

191 files changed

+4475
-1282
lines changed

clang/docs/LanguageExtensions.rst

+28
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,34 @@ OpenCL Features
17411741
17421742
Clang supports internal OpenCL extensions documented below.
17431743
1744+
``__cl_clang_bitfields``
1745+
--------------------------------
1746+
1747+
With this extension it is possible to enable bitfields in structs
1748+
or unions using the OpenCL extension pragma mechanism detailed in
1749+
`the OpenCL Extension Specification, section 1.2
1750+
<https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#extensions-overview>`_.
1751+
1752+
Use of bitfields in OpenCL kernels can result in reduced portability as struct
1753+
layout is not guaranteed to be consistent when compiled by different compilers.
1754+
If structs with bitfields are used as kernel function parameters, it can result
1755+
in incorrect functionality when the layout is different between the host and
1756+
device code.
1757+
1758+
**Example of Use**:
1759+
1760+
.. code-block:: c++
1761+
1762+
#pragma OPENCL EXTENSION __cl_clang_bitfields : enable
1763+
struct with_bitfield {
1764+
unsigned int i : 5; // compiled - no diagnostic generated
1765+
};
1766+
1767+
#pragma OPENCL EXTENSION __cl_clang_bitfields : disable
1768+
struct without_bitfield {
1769+
unsigned int i : 5; // error - bitfields are not supported
1770+
};
1771+
17441772
``__cl_clang_function_pointers``
17451773
--------------------------------
17461774

clang/include/clang/Basic/OpenCLExtensions.def

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ OPENCL_EXTENSION(cl_clang_storage_class_specifiers, true, 100)
8888
OPENCL_EXTENSION(__cl_clang_function_pointers, true, 100)
8989
OPENCL_EXTENSION(__cl_clang_variadic_functions, true, 100)
9090
OPENCL_EXTENSION(__cl_clang_non_portable_kernel_param_types, true, 100)
91+
OPENCL_EXTENSION(__cl_clang_bitfields, true, 100)
9192

9293
// AMD OpenCL extensions
9394
OPENCL_EXTENSION(cl_amd_media_ops, true, 100)

clang/lib/Analysis/CFG.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,13 @@ void CFGBuilder::findConstructionContexts(
14561456
// TODO: Handle other cases. For now, fail to find construction contexts.
14571457
break;
14581458
}
1459+
case Stmt::ParenExprClass: {
1460+
// If expression is placed into parenthesis we should propagate the parent
1461+
// construction context to subexpressions.
1462+
auto *PE = cast<ParenExpr>(Child);
1463+
findConstructionContexts(Layer, PE->getSubExpr());
1464+
break;
1465+
}
14591466
default:
14601467
break;
14611468
}

clang/lib/Basic/Targets/AMDGPU.h

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
288288
Opts["__cl_clang_variadic_functions"] = true;
289289
Opts["__cl_clang_function_pointers"] = true;
290290
Opts["__cl_clang_non_portable_kernel_param_types"] = true;
291+
Opts["__cl_clang_bitfields"] = true;
291292

292293
bool IsAMDGCN = isAMDGCN(getTriple());
293294

clang/lib/Basic/Targets/NVPTX.h

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
136136
Opts["__cl_clang_function_pointers"] = true;
137137
Opts["__cl_clang_variadic_functions"] = true;
138138
Opts["__cl_clang_non_portable_kernel_param_types"] = true;
139+
Opts["__cl_clang_bitfields"] = true;
139140

140141
Opts["cl_khr_fp64"] = true;
141142
Opts["__opencl_c_fp64"] = true;

clang/lib/CodeGen/CGDebugInfo.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -2996,8 +2996,13 @@ llvm::DIType *CGDebugInfo::CreateType(const LValueReferenceType *Ty,
29962996

29972997
llvm::DIType *CGDebugInfo::CreateType(const RValueReferenceType *Ty,
29982998
llvm::DIFile *Unit) {
2999-
return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
3000-
Ty->getPointeeType(), Unit);
2999+
llvm::dwarf::Tag Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
3000+
// DW_TAG_rvalue_reference_type was introduced in DWARF 4.
3001+
if (CGM.getCodeGenOpts().DebugStrictDwarf &&
3002+
CGM.getCodeGenOpts().DwarfVersion < 4)
3003+
Tag = llvm::dwarf::DW_TAG_reference_type;
3004+
3005+
return CreatePointerLikeType(Tag, Ty, Ty->getPointeeType(), Unit);
30013006
}
30023007

30033008
llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty,

clang/lib/Parse/ParseStmtAsm.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -577,20 +577,22 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
577577
TheTarget->createMCAsmInfo(*MRI, TT, MCOptions));
578578
// Get the instruction descriptor.
579579
std::unique_ptr<llvm::MCInstrInfo> MII(TheTarget->createMCInstrInfo());
580-
std::unique_ptr<llvm::MCObjectFileInfo> MOFI(new llvm::MCObjectFileInfo());
581580
std::unique_ptr<llvm::MCSubtargetInfo> STI(
582581
TheTarget->createMCSubtargetInfo(TT, TO.CPU, FeaturesStr));
583582
// Target MCTargetDesc may not be linked in clang-based tools.
584-
if (!MAI || !MII || !MOFI || !STI) {
583+
584+
if (!MAI || !MII || !STI) {
585585
Diag(AsmLoc, diag::err_msasm_unable_to_create_target)
586586
<< "target MC unavailable";
587587
return EmptyStmt();
588588
}
589589

590590
llvm::SourceMgr TempSrcMgr;
591-
llvm::MCContext Ctx(TheTriple, MAI.get(), MRI.get(), MOFI.get(), STI.get(),
592-
&TempSrcMgr);
593-
MOFI->initMCObjectFileInfo(Ctx, /*PIC=*/false);
591+
llvm::MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &TempSrcMgr);
592+
std::unique_ptr<llvm::MCObjectFileInfo> MOFI(
593+
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
594+
Ctx.setObjectFileInfo(MOFI.get());
595+
594596
std::unique_ptr<llvm::MemoryBuffer> Buffer =
595597
llvm::MemoryBuffer::getMemBuffer(AsmString, "<MS inline asm>");
596598

clang/lib/Sema/SemaDecl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -16881,8 +16881,10 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
1688116881
Record->setInvalidDecl();
1688216882
InvalidDecl = true;
1688316883
}
16884-
// OpenCL v1.2 s6.9.c: bitfields are not supported.
16885-
if (BitWidth) {
16884+
// OpenCL v1.2 s6.9.c: bitfields are not supported, unless Clang extension
16885+
// is enabled.
16886+
if (BitWidth && !getOpenCLOptions().isAvailableOption(
16887+
"__cl_clang_bitfields", LangOpts)) {
1688616888
Diag(Loc, diag::err_opencl_bitfields);
1688716889
InvalidDecl = true;
1688816890
}

0 commit comments

Comments
 (0)