Skip to content

Commit e5472c1

Browse files
AaronBallmandevajithvs
authored andcommitted
UPSTREAM: Work around a build issue with MSVC; NFC (llvm#142195)
Microsoft helpfully defines `THIS` to `void` in two different platform SDK headers, at least one of which is reachable via <Windows.h>. We have a user who ran into a build because of `THIS` unfortunate macro name collision. Rename the members to better match our naming conventions. Fixes llvm#142186 (cherry picked from commit 0adf6e8)
1 parent 87f0227 commit e5472c1

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,10 +1927,12 @@ private:
19271927
ArrayRef<SourceLocation> ArgLocs;
19281928

19291929
public:
1930-
static constexpr int THIS = 0;
1931-
static constexpr int INVALID = -1;
1932-
static constexpr int UNKNOWN = -2;
1933-
static constexpr int GLOBAL = -3;
1930+
enum ArgIndex {
1931+
This = 0,
1932+
Invalid = -1,
1933+
Unknown = -2,
1934+
Global = -3,
1935+
};
19341936

19351937
void setArgs(ArrayRef<IdentifierInfo*> Idents, ArrayRef<SourceLocation> Locs) {
19361938
assert(Idents.size() == params_Size);

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
665665
CanonCallee->getParamDecl(I)->getAttr<LifetimeCaptureByAttr>();
666666
CaptureAttr && isa<CXXConstructorDecl>(CanonCallee) &&
667667
llvm::any_of(CaptureAttr->params(), [](int ArgIdx) {
668-
return ArgIdx == LifetimeCaptureByAttr::THIS;
668+
return ArgIdx == LifetimeCaptureByAttr::This;
669669
}))
670670
// `lifetime_capture_by(this)` in a class constructor has the same
671671
// semantics as `lifetimebound`:

clang/lib/Sema/SemaAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
290290
// pointer-like reference types (`const T&`, `T&&`).
291291
if (PVD->getType()->isReferenceType() &&
292292
sema::isGLSPointerType(PVD->getType().getNonReferenceType())) {
293-
int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
293+
int CaptureByThis[] = {LifetimeCaptureByAttr::This};
294294
PVD->addAttr(
295295
LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
296296
}

clang/lib/Sema/SemaChecking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,8 +3232,8 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
32323232
if (!FD || Args.empty())
32333233
return;
32343234
auto GetArgAt = [&](int Idx) -> const Expr * {
3235-
if (Idx == LifetimeCaptureByAttr::GLOBAL ||
3236-
Idx == LifetimeCaptureByAttr::UNKNOWN)
3235+
if (Idx == LifetimeCaptureByAttr::Global ||
3236+
Idx == LifetimeCaptureByAttr::Unknown)
32373237
return nullptr;
32383238
if (IsMemberFunction && Idx == 0)
32393239
return ThisArg;
@@ -3248,7 +3248,7 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
32483248
for (int CapturingParamIdx : Attr->params()) {
32493249
// lifetime_capture_by(this) case is handled in the lifetimebound expr
32503250
// initialization codepath.
3251-
if (CapturingParamIdx == LifetimeCaptureByAttr::THIS &&
3251+
if (CapturingParamIdx == LifetimeCaptureByAttr::This &&
32523252
isa<CXXConstructorDecl>(FD))
32533253
continue;
32543254
Expr *Capturing = const_cast<Expr *>(GetArgAt(CapturingParamIdx));

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
39543954
}
39553955
if (!IsValid)
39563956
return nullptr;
3957-
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::INVALID);
3957+
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::Invalid);
39583958
auto *CapturedBy =
39593959
LifetimeCaptureByAttr::Create(Context, FakeParamIndices.data(), N, AL);
39603960
CapturedBy->setArgs(ParamIdents, ParamLocs);
@@ -3997,8 +3997,8 @@ void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
39973997
if (Attrs.empty())
39983998
return;
39993999
llvm::StringMap<int> NameIdxMapping = {
4000-
{"global", LifetimeCaptureByAttr::GLOBAL},
4001-
{"unknown", LifetimeCaptureByAttr::UNKNOWN}};
4000+
{"global", LifetimeCaptureByAttr::Global},
4001+
{"unknown", LifetimeCaptureByAttr::Unknown}};
40024002
int Idx = 0;
40034003
if (HasImplicitThisParam) {
40044004
NameIdxMapping["this"] = 0;

0 commit comments

Comments
 (0)