Skip to content

Commit c8a93d3

Browse files
committed
[OpenCLCpp] Avoid inferred adding address-space to function types
The default OpenCL address-space was added for function types, which was breaking transform type builtins for function types, in particular: - __remove_reference_t - __remove_cvref - __remove_pointer This change fixes SemaCXX/type-traits.cpp pass for clc++ dialect. (In feature set of clc++ and extension - ie. no VLA, _Atomic etc...) There is still unaddressed issue with address space of member-fn-ptr in __is_same trait builtin as address-space specified by user is ignored on such types. This is seperate unrelated issue and won't be addressed in this change.
1 parent 2145368 commit c8a93d3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,9 +1794,11 @@ bool Sema::CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc) {
17941794
}
17951795

17961796
// Helper to deduce addr space of a pointee type in OpenCL mode.
1797-
static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType) {
1797+
static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType,
1798+
bool IsBlock) {
17981799
if (!PointeeType->isUndeducedAutoType() && !PointeeType->isDependentType() &&
17991800
!PointeeType->isSamplerT() &&
1801+
(!PointeeType->isFunctionType() || IsBlock) &&
18001802
!PointeeType.hasAddressSpace())
18011803
PointeeType = S.getASTContext().getAddrSpaceQualType(
18021804
PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace());
@@ -1835,7 +1837,7 @@ QualType Sema::BuildPointerType(QualType T,
18351837
T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ false);
18361838

18371839
if (getLangOpts().OpenCL)
1838-
T = deduceOpenCLPointeeAddrSpace(*this, T);
1840+
T = deduceOpenCLPointeeAddrSpace(*this, T, /*IsBlock*/ false);
18391841

18401842
// In WebAssembly, pointers to reference types and pointers to tables are
18411843
// illegal.
@@ -1912,7 +1914,7 @@ QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue,
19121914
T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ true);
19131915

19141916
if (getLangOpts().OpenCL)
1915-
T = deduceOpenCLPointeeAddrSpace(*this, T);
1917+
T = deduceOpenCLPointeeAddrSpace(*this, T, /*IsBlock*/ false);
19161918

19171919
// In WebAssembly, references to reference types and tables are illegal.
19181920
if (getASTContext().getTargetInfo().getTriple().isWasm() &&
@@ -2767,7 +2769,7 @@ QualType Sema::BuildBlockPointerType(QualType T,
27672769
return QualType();
27682770

27692771
if (getLangOpts().OpenCL)
2770-
T = deduceOpenCLPointeeAddrSpace(*this, T);
2772+
T = deduceOpenCLPointeeAddrSpace(*this, T, /*IsBlock*/ true);
27712773

27722774
return Context.getBlockPointerType(T);
27732775
}

0 commit comments

Comments
 (0)