Skip to content

Commit 7936acb

Browse files
committed
([Automerger: llvm.org/main -> next] conflict merging c51095f ([InstallAPI] Add installapi specific options & diagnostics (llvm#85100...))
Merge commit 'c51095f51b77' from llvm.org/main into next Conflicts: clang/include/clang/Basic/DiagnosticIDs.h clang/lib/Basic/DiagnosticIDs.cpp clang/tools/clang-installapi/ClangInstallAPI.cpp rdar://124967750
2 parents 4e212b4 + c51095f commit 7936acb

17 files changed

+346
-54
lines changed

clang/include/clang/Basic/AllDiagnostics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/Basic/DiagnosticCrossTU.h"
2222
#include "clang/Basic/DiagnosticDriver.h"
2323
#include "clang/Basic/DiagnosticFrontend.h"
24+
#include "clang/Basic/DiagnosticInstallAPI.h"
2425
#include "clang/Basic/DiagnosticLex.h"
2526
#include "clang/Basic/DiagnosticParse.h"
2627
#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
@@ -13,6 +13,7 @@ clang_diag_gen(Common)
1313
clang_diag_gen(CrossTU)
1414
clang_diag_gen(Driver)
1515
clang_diag_gen(Frontend)
16+
clang_diag_gen(InstallAPI)
1617
clang_diag_gen(Lex)
1718
clang_diag_gen(Parse)
1819
clang_diag_gen(Refactoring)

clang/include/clang/Basic/Diagnostic.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ include "DiagnosticCommonKinds.td"
163163
include "DiagnosticCrossTUKinds.td"
164164
include "DiagnosticDriverKinds.td"
165165
include "DiagnosticFrontendKinds.td"
166+
include "DiagnosticInstallAPIKinds.td"
166167
include "DiagnosticLexKinds.td"
167168
include "DiagnosticParseKinds.td"
168169
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
DIAG_SIZE_CAS = 100,
4647
};
4748
// Start position for diagnostics.
@@ -58,7 +59,8 @@ namespace clang {
5859
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
5960
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
6061
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
61-
DIAG_START_CAS = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
62+
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
63+
DIAG_START_CAS = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_START_INSTALLAPI),
6264
DIAG_UPPER_LIMIT = DIAG_START_CAS + static_cast<int>(DIAG_SIZE_CAS)
6365
};
6466

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
@@ -50,6 +50,7 @@ struct StaticDiagInfoDescriptionStringTable {
5050
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
5151
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
5252
#include "clang/Basic/DiagnosticCASKinds.inc"
53+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
5354
// clang-format on
5455
#undef DIAG
5556
};
@@ -72,7 +73,8 @@ const StaticDiagInfoDescriptionStringTable StaticDiagInfoDescriptions = {
7273
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
7374
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
7475
#include "clang/Basic/DiagnosticCASKinds.inc"
75-
// clang-format on
76+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
77+
// clang-format on
7678
#undef DIAG
7779
};
7880

@@ -98,7 +100,8 @@ const uint32_t StaticDiagInfoDescriptionOffsets[] = {
98100
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
99101
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
100102
#include "clang/Basic/DiagnosticCASKinds.inc"
101-
// clang-format on
103+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
104+
// clang-format on
102105
#undef DIAG
103106
};
104107

@@ -177,6 +180,7 @@ VALIDATE_DIAG_SIZE(SEMA)
177180
VALIDATE_DIAG_SIZE(ANALYSIS)
178181
VALIDATE_DIAG_SIZE(REFACTORING)
179182
VALIDATE_DIAG_SIZE(CAS)
183+
VALIDATE_DIAG_SIZE(INSTALLAPI)
180184
#undef VALIDATE_DIAG_SIZE
181185
#undef STRINGIFY_NAME
182186

@@ -209,6 +213,7 @@ const StaticDiagInfoRec StaticDiagInfo[] = {
209213
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
210214
#include "clang/Basic/DiagnosticRefactoringKinds.inc"
211215
#include "clang/Basic/DiagnosticCASKinds.inc"
216+
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
212217
// clang-format on
213218
#undef DIAG
214219
};
@@ -252,6 +257,7 @@ CATEGORY(SEMA, CROSSTU)
252257
CATEGORY(ANALYSIS, SEMA)
253258
CATEGORY(REFACTORING, ANALYSIS)
254259
CATEGORY(CAS, REFACTORING)
260+
CATEGORY(INSTALLAPI, REFACTORING)
255261
#undef CATEGORY
256262

257263
// 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>

clang/test/InstallAPI/functions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// RUN: clang-installapi -target arm64-apple-macos13.1 \
66
// RUN: -I%t/usr/include -I%t/usr/local/include \
7-
// RUN: -install_name @rpath/lib/libfunctions.dylib \
7+
// RUN: -install_name @rpath/lib/libfunctions.dylib --filetype=tbd-v4 \
88
// RUN: %t/inputs.json -o %t/outputs.tbd 2>&1 | FileCheck %s --allow-empty
99
// RUN: llvm-readtapi -compare %t/outputs.tbd %t/expected.tbd 2>&1 | FileCheck %s --allow-empty
1010

clang/tools/clang-installapi/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ set(LLVM_LINK_COMPONENTS
22
Support
33
TargetParser
44
TextAPI
5+
TextAPIBinaryReader
56
Option
67
)
78

9+
set(LLVM_TARGET_DEFINITIONS InstallAPIOpts.td)
10+
tablegen(LLVM InstallAPIOpts.inc -gen-opt-parser-defs)
11+
add_public_tablegen_target(InstallAPIDriverOptions)
12+
813
add_clang_tool(clang-installapi
914
ClangInstallAPI.cpp
1015
Options.cpp
1116

17+
DEPENDS
18+
InstallAPIDriverOptions
1219
GENERATE_DRIVER
1320
)
1421

@@ -22,3 +29,4 @@ clang_target_link_libraries(clang-installapi
2229
clangTooling
2330
clangSerialization
2431
)
32+

clang/tools/clang-installapi/ClangInstallAPI.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "Options.h"
1515
#include "clang/Basic/Diagnostic.h"
1616
#include "clang/Basic/DiagnosticFrontend.h"
17-
#include "clang/Driver/Driver.h"
1817
#include "clang/Driver/DriverDiagnostic.h"
1918
#include "clang/Driver/Tool.h"
2019
#include "clang/Frontend/TextDiagnosticPrinter.h"
2120
#include "clang/InstallAPI/Frontend.h"
2221
#include "clang/InstallAPI/FrontendRecords.h"
22+
#include "clang/InstallAPI/InstallAPIDiagnostic.h"
2323
#include "clang/InstallAPI/MachO.h"
2424
#include "clang/Tooling/Tooling.h"
2525
#include "llvm/ADT/ArrayRef.h"
@@ -93,22 +93,8 @@ static bool run(ArrayRef<const char *> Args, const char *ProgName) {
9393
IntrusiveRefCntPtr<clang::FileManager> FM(
9494
new FileManager(clang::FileSystemOptions(), OverlayFileSystem));
9595

96-
// Set up driver to parse input arguments.
97-
auto DriverArgs = llvm::ArrayRef(Args).slice(1);
98-
clang::driver::Driver Driver(ProgName, llvm::sys::getDefaultTargetTriple(),
99-
*Diag, "clang installapi tool");
100-
auto TargetAndMode =
101-
clang::driver::ToolChain::getTargetAndModeFromProgramName(ProgName);
102-
Driver.setTargetAndMode(TargetAndMode);
103-
bool HasError = false;
104-
llvm::opt::InputArgList ArgList =
105-
Driver.ParseArgStrings(DriverArgs, /*UseDriverMode=*/true, HasError);
106-
if (HasError)
107-
return EXIT_FAILURE;
108-
Driver.setCheckInputsExist(false);
109-
110-
// Capture InstallAPI specific options and diagnose any option errors.
111-
Options Opts(*Diag, FM.get(), ArgList);
96+
// Capture all options and diagnose any errors.
97+
Options Opts(*Diag, FM.get(), Args, ProgName);
11298
if (Diag->hasErrorOccurred())
11399
return EXIT_FAILURE;
114100

@@ -166,6 +152,7 @@ static bool run(ArrayRef<const char *> Args, const char *ProgName) {
166152
// Write output file and perform CI cleanup.
167153
if (auto Err = TextAPIWriter::writeToStream(Out->getOS(), IF, Ctx.FT)) {
168154
Diag->Report(diag::err_cannot_open_file) << Ctx.OutputLoc;
155+
CI->clearOutputFiles(/*EraseFiles=*/true);
169156
if (auto Err = Out->discard())
170157
llvm::consumeError(std::move(Err));
171158
return EXIT_FAILURE;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- InstallAPIOpts.td ------------------------------------------------===//
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+
// This file defines the specific options for InstallAPI.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// Include the common option parsing interfaces.
14+
include "llvm/Option/OptParser.td"
15+
16+
17+
/////////
18+
// Options
19+
20+
// TextAPI options.
21+
def filetype : Joined<["--"], "filetype=">,
22+
HelpText<"Specify the output file type (tbd-v4 or tbd-v5)">;
23+
24+
// Verification options.
25+
def verify_against : Separate<["-"], "verify-against">,
26+
HelpText<"Verify the specified dynamic library/framework against the headers">;
27+
def verify_against_EQ : Joined<["--"], "verify-against=">, Alias<verify_against>;
28+
def verify_mode_EQ : Joined<["--"], "verify-mode=">,
29+
HelpText<"Specify the severity and extend of the validation. Valid modes are ErrorsOnly, ErrorsAndWarnings, and Pedantic.">;
30+
def demangle : Flag<["--", "-"], "demangle">,
31+
HelpText<"Demangle symbols when printing warnings and errors">;

0 commit comments

Comments
 (0)