Skip to content

Commit 04f48e8

Browse files
badnikhilthewilsonator
authored andcommitted
check identifier instead of strcmp directly
1 parent 445eebc commit 04f48e8

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

gen/uda.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "ir/irvar.h"
1717
#include "llvm/ADT/StringExtras.h"
1818
#include "llvm/ADT/StringSwitch.h"
19-
#include <cstring>
2019
#include <stdio.h>
2120

2221
using namespace dmd;
@@ -660,19 +659,27 @@ bool isDeviceArrayComparisonHook(Dsymbol *sym) {
660659
Module *m = sym->getModule();
661660
if (!m)
662661
return false;
662+
const ModuleDeclaration *md = m->md;
663+
if (!md)
664+
return false;
663665
// These druntime modules are host-only, but their templates (`__cmp`,
664666
// `__equals` and helpers like `isEqual`/`at`) are the lowering hooks emitted
665667
// for array `<`/`==` in device code, so they must not be skipped.
666-
const char *fqn = m->toPrettyChars();
667-
if (!strcmp(fqn, "core.internal.array.comparison") ||
668-
!strcmp(fqn, "core.internal.array.equality"))
668+
Identifier *const internal = Identifier::idPool("internal");
669+
if (md->packages.length == 3 && md->packages.ptr[0] == Id::core &&
670+
md->packages.ptr[1] == internal &&
671+
md->packages.ptr[2] == Identifier::idPool("array") &&
672+
(md->id == Identifier::idPool("comparison") ||
673+
md->id == Identifier::idPool("equality")))
669674
return true;
670675
// From core.internal.string only `dstrcmp` is a device-legal hook helper (the
671676
// `char`/string `__cmp` specialization calls it). The rest of that module
672677
// (e.g. signedToTempString) contains device-illegal code, so don't exempt the
673678
// whole module.
674-
if (!strcmp(fqn, "core.internal.string"))
675-
return sym->ident && !strcmp(sym->ident->toChars(), "dstrcmp");
679+
if (md->packages.length == 2 && md->packages.ptr[0] == Id::core &&
680+
md->packages.ptr[1] == internal &&
681+
md->id == Identifier::idPool("string"))
682+
return sym->ident == Identifier::idPool("dstrcmp");
676683
return false;
677684
}
678685

0 commit comments

Comments
 (0)