Skip to content

Commit 7d6de80

Browse files
author
Erich Keane
authored
[SYCL] Fix int-footer spec-const generation for deduced types. (#3908)
Apparently my initial implementation documented the need to do this, but never did! We collect SpecConstants (the vector), and add ones we don't know if they are SpecConstants. However, the previous implementation forgot to skip the VarDecls that were later deduced to be a different type.
1 parent 56d2563 commit 7d6de80

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4852,7 +4852,6 @@ void SYCLIntegrationFooter::addVarDecl(const VarDecl *VD) {
48524852
// rest of this file, is called during Sema instead of after it. We will
48534853
// also have to filter out after deduction later.
48544854
QualType Ty = VD->getType().getCanonicalType();
4855-
48564855
if (!Ty->isUndeducedType())
48574856
return;
48584857
}
@@ -5024,11 +5023,24 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
50245023
Policy.SuppressTypedefs = true;
50255024
Policy.SuppressUnwrittenScope = true;
50265025

5026+
llvm::SmallSet<const VarDecl *, 8> VisitedSpecConstants;
5027+
50275028
// Used to uniquely name the 'shim's as we generate the names in each
50285029
// anonymous namespace.
50295030
unsigned ShimCounter = 0;
50305031
for (const VarDecl *VD : SpecConstants) {
50315032
VD = VD->getCanonicalDecl();
5033+
5034+
// Skip if this isn't a SpecIdType. This can happen if it was a deduced
5035+
// type.
5036+
if (!Util::isSyclSpecIdType(VD->getType()))
5037+
continue;
5038+
5039+
// Skip if we've already visited this.
5040+
if (llvm::find(VisitedSpecConstants, VD) != VisitedSpecConstants.end())
5041+
continue;
5042+
5043+
VisitedSpecConstants.insert(VD);
50325044
std::string TopShim = EmitSpecIdShims(OS, ShimCounter, VD);
50335045
OS << "__SYCL_INLINE_NAMESPACE(cl) {\n";
50345046
OS << "namespace sycl {\n";

clang/test/CodeGenSYCL/integration_footer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,19 @@ specialization_id<int> AnonNSSpecID;
144144

145145
} // namespace Foo
146146

147+
// make sure we don't emit a deduced type that isn't a spec constant.
148+
enum SomeEnum { SE_A };
149+
enum AnotherEnum : unsigned int { AE_A };
150+
151+
template<SomeEnum E> struct GetThing{};
152+
template<> struct GetThing<SE_A>{
153+
static constexpr auto thing = AE_A;
154+
};
155+
156+
struct container {
157+
static constexpr auto Thing = GetThing<SE_A>::thing;
158+
};
159+
// CHECK-NOT: ::GetThing
160+
// CHECK-NOT: ::container::Thing
161+
147162
// CHECK: #include <CL/sycl/detail/spec_const_integration.hpp>

0 commit comments

Comments
 (0)