This patch fixes the following error with MSVC 16.9.2 in case of NDEBUG and LLVM_ENABLE_DUMP:
llvm/lib/CodeGen/CodeGenPrepare.cpp(2581): error C2872: 'ExtAddrMode': ambiguous symbol
llvm/include/llvm/CodeGen/TargetInstrInfo.h(86): note: could be 'llvm::ExtAddrMode'
llvm/lib/CodeGen/CodeGenPrepare.cpp(2447): note: or '`anonymous-namespace'::ExtAddrMode'
llvm/lib/CodeGen/CodeGenPrepare.cpp(2581): error C2039: 'print': is not a member of 'llvm::ExtAddrMode'
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | Please refer to the coding style, in particular:
|
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | It seems the function void ExtAddrMode::print() is related to the struct ExtAddrMode declared above inside the anonymous namespace. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | print is defined under #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP). As for the error, it seems that it is picking ExtAddrMode from TargetInstrInfo.h somehow (note that it says 'print': is not a member of 'llvm::ExtAddrMode',) though I could not find where this header is included. Are you sure you don't have any local changes that may trigger the issue? |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2578 | It should be left as it was. The intention is to allow printing if either of the macros is defined: |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | I have no any changes. Just defined NDEBUG and LLVM_ENABLE_DUMP. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 |
According to the description, the compiler complains about line 2562, which does not contain 'printf', so I assumed that you have modified the source (or, at least, have an outdated version).
Defining both of these macros does not trigger the error for me. But my build OS is Linux. I have no other ideas what could go wrong here, maybe others do? |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | I have updated the summary with more details. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | So, it is indeed confused with the same-named class from TargetInstrInfo.h. Could you track where it is included? |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | Calling ::print (with double colon) from the problematic place might workaround the issue. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | Never mind :) |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | +1 to not extending the anonymous namespace like this but instead using a qualified identifier as necessary. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | You do realize that one cannot provide qualified name for unnamed namespace, right? But please feel free to explain if I’m missing something in your comment. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | Unfortunately, I did not find the exact place. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 | Renaming TII's sounds reasonable to me. Something as general as "ExtAddrMode" should not have been added to llvm namespace in the first place (it is not that fundamental class to do so). Another option is to try to move the class into TargetInstrInfo class declaration. Either of these option will require changing backends. If the intention is to just to make it work, renaming the local class seems to be much easier task. Or, alternatively, you could introduce another namespace under the anonymous one. This will keep the class hidden, while disambiguating it with TII's class. You don't see this very often though. |
LGTM!
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 |
I was thinking we'd be dropping the using namespace llvm; but I realize now, that's going to be fragile and not really fix the underlying issue. Sorry for the noise there! I'm actually fine with these changes, the alternatives require more invasive changes that I don't think are worth it. |
llvm/lib/CodeGen/CodeGenPrepare.cpp | ||
---|---|---|
2618 |
From that point of view, looks good to me, too. |
It should be left as it was. The intention is to allow printing if either of the macros is defined:
option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)