Skip to content

Commit e4e7a7e

Browse files
committed
Revert "Add macro to suppress -Wunnecessary-virtual-specifier (#139614)"
This reverts commit 0954c9d. It breaks the build when built with gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04).
1 parent cbe9af1 commit e4e7a7e

File tree

19 files changed

+27
-40
lines changed

19 files changed

+27
-40
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class PragmaCommentDecl final
173173
PragmaMSCommentKind CommentKind)
174174
: Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
175175

176-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
176+
virtual void anchor();
177177

178178
public:
179179
static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC,
@@ -207,7 +207,7 @@ class PragmaDetectMismatchDecl final
207207
size_t ValueStart)
208208
: Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
209209

210-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
210+
virtual void anchor();
211211

212212
public:
213213
static PragmaDetectMismatchDecl *Create(const ASTContext &C,
@@ -5024,7 +5024,7 @@ class ImportDecl final : public Decl,
50245024
/// export void foo();
50255025
/// \endcode
50265026
class ExportDecl final : public Decl, public DeclContext {
5027-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5027+
virtual void anchor();
50285028

50295029
private:
50305030
friend class ASTDeclReader;

clang/include/clang/AST/DeclCXX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,7 @@ class LifetimeExtendedTemporaryDecl final
32973297

32983298
mutable APValue *Value = nullptr;
32993299

3300-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
3300+
virtual void anchor();
33013301

33023302
LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling)
33033303
: Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(),

clang/include/clang/AST/DeclFriend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ASTContext;
5252
class FriendDecl final
5353
: public Decl,
5454
private llvm::TrailingObjects<FriendDecl, TemplateParameterList *> {
55-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
55+
virtual void anchor();
5656

5757
public:
5858
using FriendUnion = llvm::PointerUnion<NamedDecl *, TypeSourceInfo *>;

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ template <typename U> class OMPDeclarativeDirective : public U {
110110
class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> {
111111
friend class OMPDeclarativeDirective<Decl>;
112112

113-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
113+
virtual void anchor();
114114

115115
OMPThreadPrivateDecl(DeclContext *DC = nullptr,
116116
SourceLocation L = SourceLocation())
@@ -418,7 +418,7 @@ class OMPRequiresDecl final : public OMPDeclarativeDirective<Decl> {
418418
friend class OMPDeclarativeDirective<Decl>;
419419
friend class ASTDeclReader;
420420

421-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
421+
virtual void anchor();
422422

423423
OMPRequiresDecl(DeclContext *DC, SourceLocation L)
424424
: OMPDeclarativeDirective<Decl>(OMPRequires, DC, L) {}
@@ -475,7 +475,7 @@ class OMPAllocateDecl final : public OMPDeclarativeDirective<Decl> {
475475
friend class OMPDeclarativeDirective<Decl>;
476476
friend class ASTDeclReader;
477477

478-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
478+
virtual void anchor();
479479

480480
OMPAllocateDecl(DeclContext *DC, SourceLocation L)
481481
: OMPDeclarativeDirective<Decl>(OMPAllocate, DC, L) {}

clang/include/clang/Driver/Action.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class BindArchAction : public Action {
267267
/// programming model implementation needs and propagates the offloading kind to
268268
/// its dependences.
269269
class OffloadAction final : public Action {
270-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
270+
virtual void anchor();
271271

272272
public:
273273
/// Type used to communicate device actions. It associates bound architecture,

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ class Sema final : public SemaBase {
895895
/// with a vtable when the vtable is emitted. Sema is final and not
896896
/// polymorphic, but the debug info size savings are so significant that it is
897897
/// worth adding a vtable just to take advantage of this optimization.
898-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
898+
virtual void anchor();
899899

900900
const LangOptions &getLangOpts() const { return LangOpts; }
901901
OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }

clang/lib/AST/ByteCode/InterpFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class InterpFrame final : public Frame {
119119
CodePtr getRetPC() const { return RetPC; }
120120

121121
/// Map a location to a source.
122-
SourceInfo getSource(CodePtr PC) const;
122+
virtual SourceInfo getSource(CodePtr PC) const;
123123
const Expr *getExpr(CodePtr PC) const;
124124
SourceLocation getLocation(CodePtr PC) const;
125125
SourceRange getRange(CodePtr PC) const;

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class CheckVarsEscapingDeclContext final
323323
CheckVarsEscapingDeclContext(CodeGenFunction &CGF,
324324
ArrayRef<const ValueDecl *> TeamsReductions)
325325
: CGF(CGF), EscapedDecls(llvm::from_range, TeamsReductions) {}
326-
~CheckVarsEscapingDeclContext() = default;
326+
virtual ~CheckVarsEscapingDeclContext() = default;
327327
void VisitDeclStmt(const DeclStmt *S) {
328328
if (!S)
329329
return;

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4783,7 +4783,7 @@ class CheckVarsEscapingUntiedTaskDeclContext final
47834783

47844784
public:
47854785
explicit CheckVarsEscapingUntiedTaskDeclContext() = default;
4786-
~CheckVarsEscapingUntiedTaskDeclContext() = default;
4786+
virtual ~CheckVarsEscapingUntiedTaskDeclContext() = default;
47874787
void VisitDeclStmt(const DeclStmt *S) {
47884788
if (!S)
47894789
return;

clang/lib/Driver/ToolChains/Hexagon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
4242
bool hasIntegratedCPP() const override { return false; }
4343
bool isLinkJob() const override { return true; }
4444

45-
void RenderExtraToolArgs(const JobAction &JA,
46-
llvm::opt::ArgStringList &CmdArgs) const;
45+
virtual void RenderExtraToolArgs(const JobAction &JA,
46+
llvm::opt::ArgStringList &CmdArgs) const;
4747
void ConstructJob(Compilation &C, const JobAction &JA,
4848
const InputInfo &Output, const InputInfoList &Inputs,
4949
const llvm::opt::ArgList &TCArgs,

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,11 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
882882
# The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful.
883883
append("-Wno-noexcept-type" CMAKE_CXX_FLAGS)
884884

885+
# LLVM has a policy of including virtual "anchor" functions to control
886+
# where the vtable is emitted. In `final` classes, these are exactly what
887+
# this warning detects: unnecessary virtual methods.
888+
add_flag_if_supported("-Wno-unnecessary-virtual-specifier" CXX_SUPPORTS_UNNECESSARY_VIRTUAL_FLAG)
889+
885890
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
886891
append("-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
887892
endif()

llvm/include/llvm/Analysis/InstSimplifyFolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class InstSimplifyFolder final : public IRBuilderFolder {
3636
TargetFolder ConstFolder;
3737
SimplifyQuery SQ;
3838

39-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
39+
virtual void anchor();
4040

4141
public:
4242
explicit InstSimplifyFolder(const DataLayout &DL) : ConstFolder(DL), SQ(DL) {}

llvm/include/llvm/Analysis/TargetFolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TargetFolder final : public IRBuilderFolder {
3939
return ConstantFoldConstant(C, DL);
4040
}
4141

42-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
42+
virtual void anchor();
4343

4444
public:
4545
explicit TargetFolder(const DataLayout &DL) : DL(DL) {}

llvm/include/llvm/IR/ConstantFolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace llvm {
2828

2929
/// ConstantFolder - Create constants with minimum, target independent, folding.
3030
class ConstantFolder final : public IRBuilderFolder {
31-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
31+
virtual void anchor();
3232

3333
public:
3434
explicit ConstantFolder() = default;

llvm/include/llvm/IR/NoFolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace llvm {
3333

3434
/// NoFolder - Create "constants" (actually, instructions) with no folding.
3535
class NoFolder final : public IRBuilderFolder {
36-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
36+
virtual void anchor();
3737

3838
public:
3939
explicit NoFolder() = default;

llvm/include/llvm/Support/Compiler.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,22 +710,4 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
710710
#define LLVM_PREFERRED_TYPE(T)
711711
#endif
712712

713-
/// \macro LLVM_VIRTUAL_ANCHOR_FUNCTION
714-
/// This macro is used to adhere to LLVM's policy that each class with a vtable
715-
/// must have at least one out-of-line virtual function. This macro allows us
716-
/// to declare such a function in `final` classes without triggering a warning.
717-
// clang-format off
718-
// Autoformatting makes this look awful.
719-
#if defined(__clang__) && __has_warning("-Wunnecessary-virtual-specifier")
720-
#define LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \
721-
_Pragma("clang diagnostic push") \
722-
_Pragma("clang diagnostic ignored \"-Wunnecessary-virtual-specifier\"") \
723-
virtual void anchor() \
724-
_Pragma("clang diagnostic pop")
725-
#else
726-
#define LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION() \
727-
virtual void anchor()
728-
#endif
729-
// clang-format on
730-
731713
#endif

llvm/include/llvm/Transforms/Scalar/GVNExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class AggregateValueExpression final : public BasicExpression {
452452
IntOperands[NumIntOperands++] = IntOperand;
453453
}
454454

455-
void allocateIntOperands(BumpPtrAllocator &Allocator) {
455+
virtual void allocateIntOperands(BumpPtrAllocator &Allocator) {
456456
assert(!IntOperands && "Operands already allocated");
457457
IntOperands = Allocator.Allocate<unsigned>(MaxIntOperands);
458458
}

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ class FatPtrConstMaterializer final : public ValueMaterializer {
12121212
ValueToValueMapTy &UnderlyingMap)
12131213
: TypeMap(TypeMap),
12141214
InternalMapper(UnderlyingMap, RF_None, TypeMap, this) {}
1215-
~FatPtrConstMaterializer() = default;
1215+
virtual ~FatPtrConstMaterializer() = default;
12161216

12171217
Value *materialize(Value *V) override;
12181218
};

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class X86InstrInfo final : public X86GenInstrInfo {
225225
X86Subtarget &Subtarget;
226226
const X86RegisterInfo RI;
227227

228-
LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
228+
virtual void anchor();
229229

230230
bool analyzeBranchImpl(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
231231
MachineBasicBlock *&FBB,

0 commit comments

Comments
 (0)