Skip to content

Commit c51095f

Browse files
authored
[InstallAPI] Add installapi specific options & diagnostics (#85100)
* A lot of `tapi installapi` options are already shared with clang, but not all. This patch handles installapi-specific options by filtering for them in the initial argv input, then passing the rest to the clang driver. * Installapi not only generates a text file but also reports to library developers when there are inconsistencies between an interface and its implementation. To allow this, add support for reporting installapi diagnostics. This will be leveraged in the verifier service.
1 parent f694f63 commit c51095f

17 files changed

+347
-55
lines changed

clang/include/clang/Basic/AllDiagnostics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Basic/DiagnosticCrossTU.h"
2121
#include "clang/Basic/DiagnosticDriver.h"
2222
#include "clang/Basic/DiagnosticFrontend.h"
23+
#include "clang/Basic/DiagnosticInstallAPI.h"
2324
#include "clang/Basic/DiagnosticLex.h"
2425
#include "clang/Basic/DiagnosticParse.h"
2526
#include "clang/Basic/DiagnosticSema.h"

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
1212
clang_diag_gen(CrossTU)
1313
clang_diag_gen(Driver)
1414
clang_diag_gen(Frontend)
15+
clang_diag_gen(InstallAPI)
1516
clang_diag_gen(Lex)
1617
clang_diag_gen(Parse)
1718
clang_diag_gen(Refactoring)

clang/include/clang/Basic/Diagnostic.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
162162
include "DiagnosticCrossTUKinds.td"
163163
include "DiagnosticDriverKinds.td"
164164
include "DiagnosticFrontendKinds.td"
165+
include "DiagnosticInstallAPIKinds.td"
165166
include "DiagnosticLexKinds.td"
166167
include "DiagnosticParseKinds.td"
167168
include "DiagnosticRefactoringKinds.td"

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace clang {
4242
DIAG_SIZE_SEMA = 4500,
4343
DIAG_SIZE_ANALYSIS = 100,
4444
DIAG_SIZE_REFACTORING = 1000,
45+
DIAG_SIZE_INSTALLAPI = 100,
4546
};
4647
// Start position for diagnostics.
4748
enum {
@@ -57,7 +58,8 @@ namespace clang {
5758
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
5859
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
5960
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
60-
DIAG_UPPER_LIMIT = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING)
61+
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
62+
DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_SIZE_INSTALLAPI)
6163
};
6264

6365
class CustomDiagInfo;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===--- DiagnosticInstallAPI.h - Diagnostics for InstallAPI-----*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
10+
#define LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
11+
12+
#include "clang/Basic/Diagnostic.h"
13+
namespace clang {
14+
namespace diag {
15+
enum {
16+
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
17+
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
18+
ENUM,
19+
#define INSTALLAPISTART
20+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
21+
#undef DIAG
22+
NUM_BUILTIN_INSTALLAPI_DIAGNOSTICS
23+
};
24+
} // namespace diag
25+
} // namespace clang
26+
#endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//==--- DiagnosticInstallAPIKinds.td - installapi diagnostics -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
//===----------------------------------------------------------------------===//
10+
// InstallAPI Diagnostics
11+
//===----------------------------------------------------------------------===//
12+
13+
let Component = "InstallAPI" in {
14+
let CategoryName = "Command line" in {
15+
def err_cannot_write_file : Error<"cannot write file '%0': %1">;
16+
def err_no_install_name : Error<"no install name specified: add -install_name <path>">;
17+
def err_no_output_file: Error<"no output file specified">;
18+
} // end of command line category.
19+
20+
} // end of InstallAPI component
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- InstallAPI/DylibVerifier.h -------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
10+
#define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
11+
12+
#include "llvm/TextAPI/Target.h"
13+
14+
namespace clang {
15+
namespace installapi {
16+
17+
/// A list of InstallAPI verification modes.
18+
enum class VerificationMode {
19+
Invalid,
20+
ErrorsOnly,
21+
ErrorsAndWarnings,
22+
Pedantic,
23+
};
24+
25+
} // namespace installapi
26+
} // namespace clang
27+
#endif // LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===--- InstallAPIDiagnostic.h - Diagnostics for InstallAPI ----*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_INSTALLAPI_INSTALLAPIDIAGNOSTIC_H
10+
#define LLVM_CLANG_INSTALLAPI_INSTALLAPIDIAGNOSTIC_H
11+
12+
#include "clang/Basic/DiagnosticInstallAPI.h"
13+
14+
#endif

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct StaticDiagInfoDescriptionStringTable {
4949
#include "clang/Basic/DiagnosticSemaKinds.inc"
5050
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
5151
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
52+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
5253
// clang-format on
5354
#undef DIAG
5455
};
@@ -70,7 +71,8 @@ const StaticDiagInfoDescriptionStringTable StaticDiagInfoDescriptions = {
7071
#include "clang/Basic/DiagnosticSemaKinds.inc"
7172
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
7273
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
73-
// clang-format on
74+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
75+
// clang-format on
7476
#undef DIAG
7577
};
7678

@@ -95,7 +97,8 @@ const uint32_t StaticDiagInfoDescriptionOffsets[] = {
9597
#include "clang/Basic/DiagnosticSemaKinds.inc"
9698
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
9799
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
98-
// clang-format on
100+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
101+
// clang-format on
99102
#undef DIAG
100103
};
101104

@@ -173,6 +176,7 @@ VALIDATE_DIAG_SIZE(CROSSTU)
173176
VALIDATE_DIAG_SIZE(SEMA)
174177
VALIDATE_DIAG_SIZE(ANALYSIS)
175178
VALIDATE_DIAG_SIZE(REFACTORING)
179+
VALIDATE_DIAG_SIZE(INSTALLAPI)
176180
#undef VALIDATE_DIAG_SIZE
177181
#undef STRINGIFY_NAME
178182

@@ -204,6 +208,7 @@ const StaticDiagInfoRec StaticDiagInfo[] = {
204208
#include "clang/Basic/DiagnosticSemaKinds.inc"
205209
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
206210
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
211+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
207212
// clang-format on
208213
#undef DIAG
209214
};
@@ -246,6 +251,7 @@ CATEGORY(CROSSTU, COMMENT)
246251
CATEGORY(SEMA, CROSSTU)
247252
CATEGORY(ANALYSIS, SEMA)
248253
CATEGORY(REFACTORING, ANALYSIS)
254+
CATEGORY(INSTALLAPI, REFACTORING)
249255
#undef CATEGORY
250256

251257
// Avoid out of bounds reads.
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/// Check non-darwin triple is rejected.
2-
// RUN: not clang-installapi -target x86_64-unknown-unknown %s 2> %t
2+
// RUN: not clang-installapi -target x86_64-unknown-unknown %s -o tmp.tbd 2> %t
33
// RUN: FileCheck --check-prefix INVALID_INSTALLAPI -input-file %t %s
44
// INVALID_INSTALLAPI: error: unsupported option 'installapi' for target 'x86_64-unknown-unknown'
5+
6+
/// Check that missing install_name is reported.
7+
// RUN: not clang-installapi -target x86_64-apple-ios-simulator %s -o tmp.tbd 2> %t
8+
// RUN: FileCheck --check-prefix INVALID_INSTALL_NAME -input-file %t %s
9+
// INVALID_INSTALL_NAME: error: no install name specified: add -install_name <path>

0 commit comments

Comments
 (0)