[clang] ed79827 - [clang][module] Improve incomplete-umbrella warning

2020-09-18 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2020-09-18T14:56:47-07:00
New Revision: ed79827aea444e6995fb3d36abc2bfd36331773c

URL: 
https://github.com/llvm/llvm-project/commit/ed79827aea444e6995fb3d36abc2bfd36331773c
DIFF: 
https://github.com/llvm/llvm-project/commit/ed79827aea444e6995fb3d36abc2bfd36331773c.diff

LOG: [clang][module] Improve incomplete-umbrella warning

Change the warning message for -Wincomplete-umbrella to report the location of 
the umbrella header;

Differential Revision: https://reviews.llvm.org/D82118

Added: 


Modified: 
clang/lib/Lex/PPLexerChange.cpp
clang/test/Modules/incomplete-umbrella.m

Removed: 




diff  --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index b7c7e2693ef1..de7b9b73ddf7 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -263,10 +263,12 @@ static void collectAllSubModulesWithUmbrellaHeader(
 }
 
 void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module ) {
-  assert(Mod.getUmbrellaHeader() && "Module must use umbrella header");
-  SourceLocation StartLoc =
-  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
-  if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header, StartLoc))
+  const Module::Header  = Mod.getUmbrellaHeader();
+  assert(UmbrellaHeader.Entry && "Module must use umbrella header");
+  const FileID  = SourceMgr.translateFile(UmbrellaHeader.Entry);
+  SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
+  if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header,
+ ExpectedHeadersLoc))
 return;
 
   ModuleMap  = getHeaderSearchInfo().getModuleMap();
@@ -291,7 +293,7 @@ void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const 
Module ) {
   // Find the relative path that would access this header.
   SmallString<128> RelativePath;
   computeRelativePath(FileMgr, Dir, *Header, RelativePath);
-  Diag(StartLoc, diag::warn_uncovered_module_header)
+  Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
   << Mod.getFullModuleName() << RelativePath;
 }
   }

diff  --git a/clang/test/Modules/incomplete-umbrella.m 
b/clang/test/Modules/incomplete-umbrella.m
index 8760b815718b..0574921203b2 100644
--- a/clang/test/Modules/incomplete-umbrella.m
+++ b/clang/test/Modules/incomplete-umbrella.m
@@ -6,8 +6,12 @@
 #import 
 @import Foo.Private;
 
-// CHECK: warning: umbrella header for module 'Foo' does not include header 
'Bar.h'
-// CHECK: warning: umbrella header for module 'Foo.Private' does not include 
header 'Baz.h'
+// CHECK: While building module 'Foo' imported from 
{{.*[/\]}}incomplete-umbrella.m:4:
+// CHECK-NEXT: In file included from :1:
+// CHECK-NEXT: {{.*Foo[.]framework[/\]Headers[/\]}}FooPublic.h:2:1: warning: 
umbrella header for module 'Foo' does not include header 'Bar.h'
+// CHECK: While building module 'Foo' imported from 
{{.*[/\]}}incomplete-umbrella.m:4:
+// CHECK-NEXT: In file included from :2:
+// CHECK-NEXT: {{.*Foo[.]framework[/\]PrivateHeaders[/\]}}Foo.h:2:1: warning: 
umbrella header for module 'Foo.Private' does not include header 'Baz.h'
 int foo() {
   int a = BAR_PUBLIC;
   int b = BAZ_PRIVATE;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f47b885 - [clang] Enable errors for undefined TARGET_OS_ macros in Darwin driver

2020-07-06 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2020-07-06T14:52:12-07:00
New Revision: f47b8851318d5ec2fa1e7867f3fdb86101cdc1da

URL: 
https://github.com/llvm/llvm-project/commit/f47b8851318d5ec2fa1e7867f3fdb86101cdc1da
DIFF: 
https://github.com/llvm/llvm-project/commit/f47b8851318d5ec2fa1e7867f3fdb86101cdc1da.diff

LOG: [clang] Enable errors for undefined TARGET_OS_ macros in Darwin driver

Add clang option `-Wundef-prefix=TARGET_OS_` and `-Werror=undef-prefix`
to Darwin driver.

Differential Revision: https://reviews.llvm.org/D83250

Added: 
clang/test/Driver/darwin-warning-options.c

Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index ad3b3a955d42..6bf42e6029eb 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -954,6 +954,10 @@ DarwinClang::DarwinClang(const Driver , const 
llvm::Triple ,
 : Darwin(D, Triple, Args) {}
 
 void DarwinClang::addClangWarningOptions(ArgStringList ) const {
+  // Always error about undefined 'TARGET_OS_*' macros.
+  CC1Args.push_back("-Wundef-prefix=TARGET_OS_");
+  CC1Args.push_back("-Werror=undef-prefix");
+
   // For modern targets, promote certain warnings to errors.
   if (isTargetWatchOSBased() || getTriple().isArch64Bit()) {
 // Always enable -Wdeprecated-objc-isa-usage and promote it

diff  --git a/clang/test/Driver/darwin-warning-options.c 
b/clang/test/Driver/darwin-warning-options.c
new file mode 100644
index ..b0a591eac820
--- /dev/null
+++ b/clang/test/Driver/darwin-warning-options.c
@@ -0,0 +1,7 @@
+// REQUIRES: system-darwin
+
+// Always error about undefined 'TARGET_OS_*' macros on Darwin.
+// RUN: %clang -### %s 2>&1 | FileCheck %s
+
+// CHECK-DAG: "-Wundef-prefix=TARGET_OS_"
+// CHECK-DAG: "-Werror=undef-prefix"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e320cf2 - [NFC][clang] Bump up DIAG_SIZE_SEMA for downstream diagnostics

2021-02-17 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2021-02-17T11:54:43-08:00
New Revision: e320cf23f0939307bca54f06039b71fcc2bffa85

URL: 
https://github.com/llvm/llvm-project/commit/e320cf23f0939307bca54f06039b71fcc2bffa85
DIFF: 
https://github.com/llvm/llvm-project/commit/e320cf23f0939307bca54f06039b71fcc2bffa85.diff

LOG: [NFC][clang] Bump up DIAG_SIZE_SEMA for downstream diagnostics

Bump DIAG_SIZE_SEMA up by 500 to accommodate extra downstream diagnostics

Differential Revision: https://reviews.llvm.org/D96888

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticIDs.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 7fd107c4add7..288504def5eb 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -36,7 +36,7 @@ namespace clang {
   DIAG_SIZE_AST   =  250,
   DIAG_SIZE_COMMENT   =  100,
   DIAG_SIZE_CROSSTU   =  100,
-  DIAG_SIZE_SEMA  = 4000,
+  DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
 };



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5aab45f - [clang][extract-api] Add global record support

2022-03-16 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-16T15:13:55-07:00
New Revision: 5aab45f430669d7d2af51386819d071b26c3c89c

URL: 
https://github.com/llvm/llvm-project/commit/5aab45f430669d7d2af51386819d071b26c3c89c
DIFF: 
https://github.com/llvm/llvm-project/commit/5aab45f430669d7d2af51386819d071b26c3c89c.diff

LOG: [clang][extract-api] Add global record support

Add facilities for extract-api:
- Structs/classes to hold collected API information: `APIRecord`, `API`
- Structs/classes for API information:
  - `AvailabilityInfo`: aggregated availbility information
  - `DeclarationFragments`: declaration fragments
- `DeclarationFragmentsBuilder`: helper class to build declaration
  fragments for various types/declarations
  - `FunctionSignature`: function signature
- Serialization: `Serializer`
- Add output file for `ExtractAPIAction`
- Refactor `clang::RawComment::getFormattedText` to provide an
  additional `getFormattedLines` for a more detailed view of comment lines
  used for the SymbolGraph format

Add support for global records (global variables and functions)
- Add `GlobalRecord` based on `APIRecord` to store global records'
  information
- Implement `VisitVarDecl` and `VisitFunctionDecl` in `ExtractAPIVisitor` to
  collect information
- Implement serialization for global records
- Add test case for global records

Differential Revision: https://reviews.llvm.org/D119479

Added: 
clang/include/clang/SymbolGraph/API.h
clang/include/clang/SymbolGraph/AvailabilityInfo.h
clang/include/clang/SymbolGraph/DeclarationFragments.h
clang/include/clang/SymbolGraph/FrontendActions.h
clang/include/clang/SymbolGraph/Serialization.h
clang/lib/SymbolGraph/API.cpp
clang/lib/SymbolGraph/CMakeLists.txt
clang/lib/SymbolGraph/DeclarationFragments.cpp
clang/lib/SymbolGraph/ExtractAPIConsumer.cpp
clang/lib/SymbolGraph/Serialization.cpp
clang/test/SymbolGraph/global_record.c

Modified: 
clang/include/clang/AST/RawCommentList.h
clang/include/clang/Frontend/FrontendActions.h
clang/lib/AST/RawCommentList.cpp
clang/lib/CMakeLists.txt
clang/lib/Frontend/CMakeLists.txt
clang/lib/FrontendTool/CMakeLists.txt
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
clang/test/Driver/extract-api.c

Removed: 
clang/lib/Frontend/ExtractAPIConsumer.cpp



diff  --git a/clang/include/clang/AST/RawCommentList.h 
b/clang/include/clang/AST/RawCommentList.h
index a18432c2b7682..1bb8d7ce40a90 100644
--- a/clang/include/clang/AST/RawCommentList.h
+++ b/clang/include/clang/AST/RawCommentList.h
@@ -139,6 +139,21 @@ class RawComment {
   std::string getFormattedText(const SourceManager ,
DiagnosticsEngine ) const;
 
+  struct CommentLine {
+std::string Text;
+PresumedLoc Begin;
+PresumedLoc End;
+
+CommentLine(StringRef Text, PresumedLoc Begin, PresumedLoc End)
+: Text(Text), Begin(Begin), End(End) {}
+  };
+
+  /// Returns sanitized comment text as separated lines with locations in
+  /// source, suitable for further processing and rendering requiring source
+  /// locations.
+  std::vector getFormattedLines(const SourceManager ,
+ DiagnosticsEngine ) const;
+
   /// Parse the comment, assuming it is attached to decl \c D.
   comments::FullComment *parse(const ASTContext ,
const Preprocessor *PP, const Decl *D) const;

diff  --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index 8eceb81723d23..9b5b757034a6a 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -271,12 +271,6 @@ class PrintDependencyDirectivesSourceMinimizerAction : 
public FrontendAction {
   bool usesPreprocessorOnly() const override { return true; }
 };
 
-class ExtractAPIAction : public ASTFrontendAction {
-protected:
-  std::unique_ptr CreateASTConsumer(CompilerInstance ,
- StringRef InFile) override;
-};
-
 
//===--===//
 // Preprocessor Actions
 
//===--===//

diff  --git a/clang/include/clang/SymbolGraph/API.h 
b/clang/include/clang/SymbolGraph/API.h
new file mode 100644
index 0..39cc7a699ed86
--- /dev/null
+++ b/clang/include/clang/SymbolGraph/API.h
@@ -0,0 +1,138 @@
+//===- SymbolGraph/API.h *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// \brief Defines SymbolGraph API 

[clang] fa331da - [FIX][clang-extract-api] Fix scope naming violation

2022-03-16 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-16T16:04:44-07:00
New Revision: fa331da8fb7ea915d29e0834c7acc7a01eccb4e6

URL: 
https://github.com/llvm/llvm-project/commit/fa331da8fb7ea915d29e0834c7acc7a01eccb4e6
DIFF: 
https://github.com/llvm/llvm-project/commit/fa331da8fb7ea915d29e0834c7acc7a01eccb4e6.diff

LOG: [FIX][clang-extract-api] Fix scope naming violation

Added: 


Modified: 
clang/include/clang/SymbolGraph/API.h
clang/include/clang/SymbolGraph/Serialization.h
clang/lib/SymbolGraph/API.cpp
clang/lib/SymbolGraph/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/include/clang/SymbolGraph/API.h 
b/clang/include/clang/SymbolGraph/API.h
index 39cc7a699ed86..541673f36b223 100644
--- a/clang/include/clang/SymbolGraph/API.h
+++ b/clang/include/clang/SymbolGraph/API.h
@@ -88,9 +88,9 @@ struct GlobalRecord : APIRecord {
   }
 };
 
-class API {
+class APISet {
 public:
-  API(const llvm::Triple , const LangOptions )
+  APISet(const llvm::Triple , const LangOptions )
   : Target(Target), LangOpts(LangOpts) {}
 
   const llvm::Triple () const { return Target; }

diff  --git a/clang/include/clang/SymbolGraph/Serialization.h 
b/clang/include/clang/SymbolGraph/Serialization.h
index 335f5f779314a..6452f6e93750b 100644
--- a/clang/include/clang/SymbolGraph/Serialization.h
+++ b/clang/include/clang/SymbolGraph/Serialization.h
@@ -30,7 +30,7 @@ struct SerializerOption {
 
 class Serializer {
 public:
-  Serializer(const API , SerializerOption Options = {})
+  Serializer(const APISet , SerializerOption Options = {})
   : API(API), Options(Options) {}
 
   Object serialize();
@@ -44,7 +44,7 @@ class Serializer {
 
   bool shouldSkip(const APIRecord ) const;
 
-  const API 
+  const APISet 
   SerializerOption Options;
   Array Symbols;
   Array Relationships;

diff  --git a/clang/lib/SymbolGraph/API.cpp b/clang/lib/SymbolGraph/API.cpp
index a4e0e219d4d33..4066428c97fc9 100644
--- a/clang/lib/SymbolGraph/API.cpp
+++ b/clang/lib/SymbolGraph/API.cpp
@@ -23,11 +23,13 @@ namespace symbolgraph {
 
 APIRecord::~APIRecord() {}
 
-GlobalRecord *
-API::addGlobal(GVKind Kind, StringRef Name, StringRef USR, PresumedLoc Loc,
-   const AvailabilityInfo , LinkageInfo Linkage,
-   const DocComment , DeclarationFragments Fragments,
-   DeclarationFragments SubHeading, FunctionSignature Signature) {
+GlobalRecord *APISet::addGlobal(GVKind Kind, StringRef Name, StringRef USR,
+PresumedLoc Loc,
+const AvailabilityInfo ,
+LinkageInfo Linkage, const DocComment ,
+DeclarationFragments Fragments,
+DeclarationFragments SubHeading,
+FunctionSignature Signature) {
   auto Result = Globals.insert({Name, nullptr});
   if (Result.second) {
 GlobalRecord *Record = new (Allocator)
@@ -38,32 +40,33 @@ API::addGlobal(GVKind Kind, StringRef Name, StringRef USR, 
PresumedLoc Loc,
   return Result.first->second;
 }
 
-GlobalRecord *API::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
-const AvailabilityInfo ,
-LinkageInfo Linkage, const DocComment ,
-DeclarationFragments Fragments,
-DeclarationFragments SubHeading) {
+GlobalRecord *
+APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo , LinkageInfo Linkage,
+ const DocComment , DeclarationFragments Fragments,
+ DeclarationFragments SubHeading) {
   return addGlobal(GVKind::Variable, Name, USR, Loc, Availability, Linkage,
Comment, Fragments, SubHeading, {});
 }
 
-GlobalRecord *API::addFunction(StringRef Name, StringRef USR, PresumedLoc Loc,
-   const AvailabilityInfo ,
-   LinkageInfo Linkage, const DocComment ,
-   DeclarationFragments Fragments,
-   DeclarationFragments SubHeading,
-   FunctionSignature Signature) {
+GlobalRecord *
+APISet::addFunction(StringRef Name, StringRef USR, PresumedLoc Loc,
+const AvailabilityInfo , LinkageInfo Linkage,
+const DocComment , DeclarationFragments Fragments,
+DeclarationFragments SubHeading,
+FunctionSignature Signature) {
   return addGlobal(GVKind::Function, Name, USR, Loc, Availability, Linkage,
Comment, Fragments, SubHeading, Signature);
 }
 
-StringRef API::recordUSR(const Decl *D) {
+StringRef APISet::recordUSR(const Decl *D) {
   SmallString<128> USR;
   index::generateUSRForDecl(D, USR);
   return copyString(USR);
 }
 
-StringRef 

[clang] 3840082 - [FIX][NFC] Fix a test case in clang/SymbolGraph

2022-03-16 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-16T17:19:35-07:00
New Revision: 3840082ab509490f16766cd8c155a1cf4b606fec

URL: 
https://github.com/llvm/llvm-project/commit/3840082ab509490f16766cd8c155a1cf4b606fec
DIFF: 
https://github.com/llvm/llvm-project/commit/3840082ab509490f16766cd8c155a1cf4b606fec.diff

LOG: [FIX][NFC] Fix a test case in clang/SymbolGraph

The clang/SymbolGraph/global_record.c test case explicitly diffs the
clang version in use, which causes failures. Fix the issue by normalize
the `generator` field before checking the output.

Added: 


Modified: 
clang/test/SymbolGraph/global_record.c

Removed: 




diff  --git a/clang/test/SymbolGraph/global_record.c 
b/clang/test/SymbolGraph/global_record.c
index ba4bf967e6302..fa577ee29b17d 100644
--- a/clang/test/SymbolGraph/global_record.c
+++ b/clang/test/SymbolGraph/global_record.c
@@ -4,7 +4,9 @@
 // RUN: %t/reference.output.json
 // RUN: %clang -extract-api -target arm64-apple-macosx \
 // RUN: %t/input.c -o %t/output.json | FileCheck -allow-empty %s
-// RUN: sed -e "s@\"generator\": \"clang.*\"@\"generator\": \"clang\"@g" \
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
 // RUN: %t/output.json >> %t/output-normalized.json
 // RUN: 
diff  %t/reference.output.json %t/output-normalized.json
 
@@ -32,7 +34,7 @@ char unavailable __attribute__((unavailable));
   "minor": 5,
   "patch": 3
 },
-"generator": "clang"
+"generator": "?"
   },
   "module": {
 "name": "",



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 89f6b26 - [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-22 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-22T13:21:57-07:00
New Revision: 89f6b26f1beb2c1344f5cfeb34e405128544c76b

URL: 
https://github.com/llvm/llvm-project/commit/89f6b26f1beb2c1344f5cfeb34e405128544c76b
DIFF: 
https://github.com/llvm/llvm-project/commit/89f6b26f1beb2c1344f5cfeb34e405128544c76b.diff

LOG: [clang][extract-api] Refactor ExtractAPI and improve docs

- The name SymbolGraph is inappropriate and confusing for the new library
  for clang-extract-api. Refactor and rename things to make it clear that
  ExtractAPI is the core functionality and SymbolGraph is one serializer
  for the API information.
- Add documentation comments to ExtractAPI classes and methods to improve
  readability and clearness of the ExtractAPI work.

Differential Revision: https://reviews.llvm.org/D122160

Added: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/AvailabilityInfo.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/FrontendActions.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/CMakeLists.txt
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/global_record.c

Modified: 
clang/lib/CMakeLists.txt
clang/lib/FrontendTool/CMakeLists.txt
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Removed: 
clang/include/clang/SymbolGraph/API.h
clang/include/clang/SymbolGraph/AvailabilityInfo.h
clang/include/clang/SymbolGraph/DeclarationFragments.h
clang/include/clang/SymbolGraph/FrontendActions.h
clang/include/clang/SymbolGraph/Serialization.h
clang/lib/SymbolGraph/API.cpp
clang/lib/SymbolGraph/CMakeLists.txt
clang/lib/SymbolGraph/DeclarationFragments.cpp
clang/lib/SymbolGraph/ExtractAPIConsumer.cpp
clang/lib/SymbolGraph/Serialization.cpp
clang/test/SymbolGraph/global_record.c



diff  --git a/clang/include/clang/SymbolGraph/API.h 
b/clang/include/clang/ExtractAPI/API.h
similarity index 57%
rename from clang/include/clang/SymbolGraph/API.h
rename to clang/include/clang/ExtractAPI/API.h
index ffcc03758f4d2..5ba3cf7268d88 100644
--- a/clang/include/clang/SymbolGraph/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -1,4 +1,4 @@
-//===- SymbolGraph/API.h *- C++ 
-*-===//
+//===- ExtractAPI/API.h -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,18 +7,22 @@
 
//===--===//
 ///
 /// \file
-/// \brief Defines SymbolGraph API records.
+/// This file defines the APIRecord-based structs and the APISet class.
+///
+/// Clang ExtractAPI is a tool to collect API information from a given set of
+/// header files. The structures in this file describe data representations of
+/// the API information collected for various kinds of symbols.
 ///
 
//===--===//
 
-#ifndef LLVM_CLANG_SYMBOLGRAPH_API_H
-#define LLVM_CLANG_SYMBOLGRAPH_API_H
+#ifndef LLVM_CLANG_EXTRACTAPI_API_H
+#define LLVM_CLANG_EXTRACTAPI_API_H
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/SymbolGraph/AvailabilityInfo.h"
-#include "clang/SymbolGraph/DeclarationFragments.h"
+#include "clang/ExtractAPI/AvailabilityInfo.h"
+#include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
@@ -27,18 +31,43 @@
 #include 
 
 namespace clang {
-namespace symbolgraph {
+namespace extractapi {
 
+/// DocComment is a vector of RawComment::CommentLine.
+///
+/// Each line represents one line of striped documentation comment,
+/// with source range information. This simplifies calculating the source
+/// location of a character in the doc comment for pointing back to the source
+/// file.
+/// e.g.
+/// \code
+///   /// This is a documentation comment
+///   ^~'  First line.
+///   /// with multiple lines.
+///   ^~~' Second line.
+/// \endcode
 using DocComment = std::vector;
 
+/// The base representation of an API record. Holds common symbol information.
 struct APIRecord {
   StringRef Name;
   StringRef USR;
   PresumedLoc Location;
   AvailabilityInfo Availability;
   LinkageInfo Linkage;
+
+  /// Documentation comment lines attached to this symbol declaration.
   DocComment 

[clang] b62d402 - [NFC][clang][extract-api] Use proper name string for Objective-C language

2022-03-22 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-22T14:18:26-07:00
New Revision: b62d40216f4742d46b1d2942617cf567e74272c4

URL: 
https://github.com/llvm/llvm-project/commit/b62d40216f4742d46b1d2942617cf567e74272c4
DIFF: 
https://github.com/llvm/llvm-project/commit/b62d40216f4742d46b1d2942617cf567e74272c4.diff

LOG: [NFC][clang][extract-api] Use proper name string for Objective-C language

Change the Symbol Graph serializer for ExtractAPI to use `objective-c`
for the language name string for Objective-C, to align with clang
frontend standards.

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index b0bc2034fe970..b12d911390426 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -159,7 +159,7 @@ StringRef getLanguageName(const LangOptions ) {
   case Language::C:
 return "c";
   case Language::ObjC:
-return "objc";
+return "objective-c";
 
   // Unsupported language currently
   case Language::CXX:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 71b4c22 - [clang][extract-api] Add enum support

2022-03-23 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-23T09:41:21-07:00
New Revision: 71b4c22612a06c950d31db83a45dee7412a64c64

URL: 
https://github.com/llvm/llvm-project/commit/71b4c22612a06c950d31db83a45dee7412a64c64
DIFF: 
https://github.com/llvm/llvm-project/commit/71b4c22612a06c950d31db83a45dee7412a64c64.diff

LOG: [clang][extract-api] Add enum support

Add support for enum records
- Add `EnumConstantRecord` and `EnumRecord` to store API information for
  enums
- Implement `VisitEnumDecl` in `ExtractAPIVisitor`
- Implement serializatin for enum records and `MemberOf` relationship
- Add test case for enum records
- Few other improvements

Depends on D122160

Differential Revision: https://reviews.llvm.org/D121873

Added: 
clang/test/ExtractAPI/enum.c

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 5ba3cf7268d88..52b78d9188a1c 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -30,6 +30,25 @@
 #include "llvm/Support/Casting.h"
 #include 
 
+namespace {
+
+/// \brief A custom deleter used for ``std::unique_ptr`` to APIRecords stored
+/// in the BumpPtrAllocator.
+///
+/// \tparam T the exact type of the APIRecord subclass.
+template  struct UniquePtrBumpPtrAllocatorDeleter {
+  void operator()(T *Instance) { Instance->~T(); }
+};
+
+/// A unique pointer to an APIRecord stored in the BumpPtrAllocator.
+///
+/// \tparam T the exact type of the APIRecord subclass.
+template 
+using APIRecordUniquePtr =
+std::unique_ptr>;
+
+} // anonymous namespace
+
 namespace clang {
 namespace extractapi {
 
@@ -73,6 +92,8 @@ struct APIRecord {
   /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
   enum RecordKind {
 RK_Global,
+RK_EnumConstant,
+RK_Enum,
   };
 
 private:
@@ -125,6 +146,36 @@ struct GlobalRecord : APIRecord {
   virtual void anchor();
 };
 
+/// This holds information associated with enum constants.
+struct EnumConstantRecord : APIRecord {
+  EnumConstantRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo ,
+ const DocComment ,
+ DeclarationFragments Declaration,
+ DeclarationFragments SubHeading)
+  : APIRecord(RK_EnumConstant, Name, USR, Loc, Availability,
+  LinkageInfo::none(), Comment, Declaration, SubHeading) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_EnumConstant;
+  }
+};
+
+/// This holds information associated with enums.
+struct EnumRecord : APIRecord {
+  SmallVector> Constants;
+
+  EnumRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo , const DocComment ,
+ DeclarationFragments Declaration, DeclarationFragments SubHeading)
+  : APIRecord(RK_Enum, Name, USR, Loc, Availability, LinkageInfo::none(),
+  Comment, Declaration, SubHeading) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_Enum;
+  }
+};
+
 /// APISet holds the set of API records collected from given inputs.
 class APISet {
 public:
@@ -166,28 +217,41 @@ class APISet {
 DeclarationFragments SubHeading,
 FunctionSignature Signature);
 
-private:
-  /// \brief A custom deleter used for ``std::unique_ptr`` to APIRecords stored
-  /// in the BumpPtrAllocator.
+  /// Create and add an enum constant record into the API set.
   ///
-  /// \tparam T the exact type of the APIRecord subclass.
-  template  struct UniquePtrBumpPtrAllocatorDeleter {
-void operator()(T *Instance) { Instance->~T(); }
-  };
-
-public:
-  /// A unique pointer to an APIRecord stored in the BumpPtrAllocator.
+  /// Note: the caller is responsible for keeping the StringRef \p Name and
+  /// \p USR alive. APISet::copyString provides a way to copy strings into
+  /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
+  /// to generate the USR for \c D and keep it alive in APISet.
+  EnumConstantRecord *addEnumConstant(EnumRecord *Enum, StringRef Name,
+  StringRef USR, PresumedLoc Loc,
+  const AvailabilityInfo ,
+  const DocComment ,
+  DeclarationFragments Declaration,
+  DeclarationFragments SubHeading);
+
+  /// Create and add an enum record into the 

[clang] 5bb5704 - [clang][extract-api] Add struct support

2022-03-23 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-23T09:45:06-07:00
New Revision: 5bb5704c1b35023b8a6217a6eb7d98a47efe1ca2

URL: 
https://github.com/llvm/llvm-project/commit/5bb5704c1b35023b8a6217a6eb7d98a47efe1ca2
DIFF: 
https://github.com/llvm/llvm-project/commit/5bb5704c1b35023b8a6217a6eb7d98a47efe1ca2.diff

LOG: [clang][extract-api] Add struct support

- Add `StructFieldRecord` and `StructRecord` to store API information
  for structs
- Implement `VisitRecordDecl` in `ExtractAPIVisitor`
- Implement Symbol Graph serialization for struct records.
- Add test case for struct records.

Depends on D121873

Differential Revision: https://reviews.llvm.org/D122202

Added: 
clang/test/ExtractAPI/struct.c

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 52b78d9188a1c..e8f9219358ccf 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -94,6 +94,8 @@ struct APIRecord {
 RK_Global,
 RK_EnumConstant,
 RK_Enum,
+RK_StructField,
+RK_Struct,
   };
 
 private:
@@ -176,6 +178,36 @@ struct EnumRecord : APIRecord {
   }
 };
 
+/// This holds information associated with struct fields.
+struct StructFieldRecord : APIRecord {
+  StructFieldRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+const AvailabilityInfo ,
+const DocComment , DeclarationFragments 
Declaration,
+DeclarationFragments SubHeading)
+  : APIRecord(RK_StructField, Name, USR, Loc, Availability,
+  LinkageInfo::none(), Comment, Declaration, SubHeading) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_StructField;
+  }
+};
+
+/// This holds information associated with structs.
+struct StructRecord : APIRecord {
+  SmallVector> Fields;
+
+  StructRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+   const AvailabilityInfo , const DocComment ,
+   DeclarationFragments Declaration,
+   DeclarationFragments SubHeading)
+  : APIRecord(RK_Struct, Name, USR, Loc, Availability, LinkageInfo::none(),
+  Comment, Declaration, SubHeading) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_Struct;
+  }
+};
+
 /// APISet holds the set of API records collected from given inputs.
 class APISet {
 public:
@@ -242,6 +274,31 @@ class APISet {
   DeclarationFragments Declaration,
   DeclarationFragments SubHeading);
 
+  /// Create and add a struct field record into the API set.
+  ///
+  /// Note: the caller is responsible for keeping the StringRef \p Name and
+  /// \p USR alive. APISet::copyString provides a way to copy strings into
+  /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
+  /// to generate the USR for \c D and keep it alive in APISet.
+  StructFieldRecord *addStructField(StructRecord *Struct, StringRef Name,
+StringRef USR, PresumedLoc Loc,
+const AvailabilityInfo ,
+const DocComment ,
+DeclarationFragments Declaration,
+DeclarationFragments SubHeading);
+
+  /// Create and add a struct record into the API set.
+  ///
+  /// Note: the caller is responsible for keeping the StringRef \p Name and
+  /// \p USR alive. APISet::copyString provides a way to copy strings into
+  /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
+  /// to generate the USR for \c D and keep it alive in APISet.
+  StructRecord *addStruct(StringRef Name, StringRef USR, PresumedLoc Loc,
+  const AvailabilityInfo ,
+  const DocComment ,
+  DeclarationFragments Declaration,
+  DeclarationFragments SubHeading);
+
   /// A map to store the set of GlobalRecord%s with the declaration name as the
   /// key.
   using GlobalRecordMap =
@@ -252,6 +309,11 @@ class APISet {
   using EnumRecordMap =
   llvm::MapVector>;
 
+  /// A map to store the set of StructRecord%s with the declaration name as the
+  /// key.
+  using StructRecordMap =
+  llvm::MapVector>;
+
   /// Get the target triple for the ExtractAPI invocation.
   const llvm::Triple () const { return Target; }
 
@@ -260,6 +322,7 @@ class APISet {
 
   const GlobalRecordMap () const { 

[clang] d1d34ba - [clang][extract-api] Add Objective-C protocol support

2022-03-29 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-29T14:44:49-07:00
New Revision: d1d34bafef56b732b461e12032eaf030e609f55a

URL: 
https://github.com/llvm/llvm-project/commit/d1d34bafef56b732b461e12032eaf030e609f55a
DIFF: 
https://github.com/llvm/llvm-project/commit/d1d34bafef56b732b461e12032eaf030e609f55a.diff

LOG: [clang][extract-api] Add Objective-C protocol support

Add support for Objective-C protocol declarations in ExtractAPI.

Depends on D122446

Differential Revision: https://reviews.llvm.org/D122511

Added: 
clang/test/ExtractAPI/objc_protocol.m

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index a2a462be42cd3..57397e7c256ea 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -82,6 +82,7 @@ struct APIRecord {
 RK_ObjCIvar,
 RK_ObjCMethod,
 RK_ObjCInterface,
+RK_ObjCProtocol,
   };
 
 private:
@@ -354,6 +355,25 @@ struct ObjCInterfaceRecord : ObjCContainerRecord {
   virtual void anchor();
 };
 
+/// This holds information associated with Objective-C protocols.
+struct ObjCProtocolRecord : ObjCContainerRecord {
+  ObjCProtocolRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo ,
+ const DocComment ,
+ DeclarationFragments Declaration,
+ DeclarationFragments SubHeading)
+  : ObjCContainerRecord(RK_ObjCProtocol, Name, USR, Loc, Availability,
+LinkageInfo::none(), Comment, Declaration,
+SubHeading) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_ObjCProtocol;
+  }
+
+private:
+  virtual void anchor();
+};
+
 /// APISet holds the set of API records collected from given inputs.
 class APISet {
 public:
@@ -497,6 +517,19 @@ class APISet {
   DeclarationFragments SubHeading,
   ObjCInstanceVariableRecord::AccessControl Access);
 
+  /// Create and add an Objective-C protocol record into the API set.
+  ///
+  /// Note: the caller is responsible for keeping the StringRef \p Name and
+  /// \p USR alive. APISet::copyString provides a way to copy strings into
+  /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
+  /// to generate the USR for \c D and keep it alive in APISet.
+  ObjCProtocolRecord *addObjCProtocol(StringRef Name, StringRef USR,
+  PresumedLoc Loc,
+  const AvailabilityInfo ,
+  const DocComment ,
+  DeclarationFragments Declaration,
+  DeclarationFragments SubHeading);
+
   /// A map to store the set of GlobalRecord%s with the declaration name as the
   /// key.
   using GlobalRecordMap =
@@ -516,6 +549,11 @@ class APISet {
   using ObjCInterfaceRecordMap =
   llvm::MapVector>;
 
+  /// A map to store the set of ObjCProtocolRecord%s with the declaration name
+  /// as the key.
+  using ObjCProtocolRecordMap =
+  llvm::MapVector>;
+
   /// Get the target triple for the ExtractAPI invocation.
   const llvm::Triple () const { return Target; }
 
@@ -528,6 +566,9 @@ class APISet {
   const ObjCInterfaceRecordMap () const {
 return ObjCInterfaces;
   }
+  const ObjCProtocolRecordMap () const {
+return ObjCProtocols;
+  }
 
   /// Generate and store the USR of declaration \p D.
   ///
@@ -557,6 +598,7 @@ class APISet {
   EnumRecordMap Enums;
   StructRecordMap Structs;
   ObjCInterfaceRecordMap ObjCInterfaces;
+  ObjCProtocolRecordMap ObjCProtocols;
 };
 
 } // namespace extractapi

diff  --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h 
b/clang/include/clang/ExtractAPI/DeclarationFragments.h
index f147abb4f425c..ca5b014a1f5a5 100644
--- a/clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -217,6 +217,11 @@ class DeclarationFragmentsBuilder {
   static DeclarationFragments
   getFragmentsForObjCProperty(const ObjCPropertyDecl *);
 
+  /// Build DeclarationFragments for an Objective-C protocol declaration
+  /// ObjCProtocolDecl.
+  static DeclarationFragments
+  getFragmentsForObjCProtocol(const ObjCProtocolDecl *);
+
   /// Build sub-heading fragments for a NamedDecl.
   static DeclarationFragments getSubHeading(const NamedDecl *);
 

diff  --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp
index 2456022523adb..1c9314c0be10d 100644
--- a/clang/lib/ExtractAPI/API.cpp
+++ 

[clang] 9b36e12 - [clang][extract-api] Add Objective-C interface support

2022-03-29 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-29T14:29:39-07:00
New Revision: 9b36e126fdb1da4d7e255e089ef225dfb130ef63

URL: 
https://github.com/llvm/llvm-project/commit/9b36e126fdb1da4d7e255e089ef225dfb130ef63
DIFF: 
https://github.com/llvm/llvm-project/commit/9b36e126fdb1da4d7e255e089ef225dfb130ef63.diff

LOG: [clang][extract-api] Add Objective-C interface support

Add support for Objective-C interface declarations in ExtractAPI.

Depends on D122495

Differential Revision: https://reviews.llvm.org/D122446

Added: 
clang/test/ExtractAPI/objc_interface.m

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index b22d110475908..a2a462be42cd3 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -19,6 +19,7 @@
 #define LLVM_CLANG_EXTRACTAPI_API_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/ExtractAPI/AvailabilityInfo.h"
@@ -77,6 +78,10 @@ struct APIRecord {
 RK_Enum,
 RK_StructField,
 RK_Struct,
+RK_ObjCProperty,
+RK_ObjCIvar,
+RK_ObjCMethod,
+RK_ObjCInterface,
   };
 
 private:
@@ -201,6 +206,154 @@ struct StructRecord : APIRecord {
   virtual void anchor();
 };
 
+/// This holds information associated with Objective-C properties.
+struct ObjCPropertyRecord : APIRecord {
+  /// The attributes associated with an Objective-C property.
+  enum AttributeKind : unsigned {
+NoAttr = 0,
+ReadOnly = 1,
+Class = 1 << 1,
+Dynamic = 1 << 2,
+  };
+
+  AttributeKind Attributes;
+  StringRef GetterName;
+  StringRef SetterName;
+  bool IsOptional;
+
+  ObjCPropertyRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo ,
+ const DocComment ,
+ DeclarationFragments Declaration,
+ DeclarationFragments SubHeading, AttributeKind Attributes,
+ StringRef GetterName, StringRef SetterName,
+ bool IsOptional)
+  : APIRecord(RK_ObjCProperty, Name, USR, Loc, Availability,
+  LinkageInfo::none(), Comment, Declaration, SubHeading),
+Attributes(Attributes), GetterName(GetterName), SetterName(SetterName),
+IsOptional(IsOptional) {}
+
+  bool isReadOnly() const { return Attributes & ReadOnly; }
+  bool isDynamic() const { return Attributes & Dynamic; }
+  bool isClassProperty() const { return Attributes & Class; }
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_ObjCProperty;
+  }
+
+private:
+  virtual void anchor();
+};
+
+/// This holds information associated with Objective-C instance variables.
+struct ObjCInstanceVariableRecord : APIRecord {
+  using AccessControl = ObjCIvarDecl::AccessControl;
+  AccessControl Access;
+
+  ObjCInstanceVariableRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo ,
+ const DocComment ,
+ DeclarationFragments Declaration,
+ DeclarationFragments SubHeading,
+ AccessControl Access)
+  : APIRecord(RK_ObjCIvar, Name, USR, Loc, Availability,
+  LinkageInfo::none(), Comment, Declaration, SubHeading),
+Access(Access) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_ObjCIvar;
+  }
+
+private:
+  virtual void anchor();
+};
+
+/// This holds information associated with Objective-C methods.
+struct ObjCMethodRecord : APIRecord {
+  FunctionSignature Signature;
+  bool IsInstanceMethod;
+
+  ObjCMethodRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+   const AvailabilityInfo ,
+   const DocComment , DeclarationFragments Declaration,
+   DeclarationFragments SubHeading, FunctionSignature 
Signature,
+   bool IsInstanceMethod)
+  : APIRecord(RK_ObjCMethod, Name, USR, Loc, Availability,
+  LinkageInfo::none(), Comment, Declaration, SubHeading),
+Signature(Signature), IsInstanceMethod(IsInstanceMethod) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_ObjCMethod;
+  }
+
+private:
+  virtual void anchor();
+};
+
+/// This represents a reference to another symbol that might come from external
+/// sources.
+struct SymbolReference {
+  

[clang] 15bf0e5 - [clang][extract-api] Use correct language info from inputs

2022-03-29 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-29T10:06:08-07:00
New Revision: 15bf0e567375c977cf7d7b48465eb1561e890b54

URL: 
https://github.com/llvm/llvm-project/commit/15bf0e567375c977cf7d7b48465eb1561e890b54
DIFF: 
https://github.com/llvm/llvm-project/commit/15bf0e567375c977cf7d7b48465eb1561e890b54.diff

LOG: [clang][extract-api] Use correct language info from inputs

The current way of getting the `clang::Language` from `LangOptions` does
not handle Objective-C correctly because `clang::Language::ObjC` does
not correspond to any `LangStandard`. This patch passes the correct
`Language` from the frontend input information.

Differential Revision: https://reviews.llvm.org/D122495

Added: 
clang/test/ExtractAPI/language.c

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index eb72450f87d23..b22d110475908 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -309,8 +309,8 @@ class APISet {
   /// Get the target triple for the ExtractAPI invocation.
   const llvm::Triple () const { return Target; }
 
-  /// Get the language options used to parse the APIs.
-  const LangOptions () const { return LangOpts; }
+  /// Get the language used by the APIs.
+  Language getLanguage() const { return Lang; }
 
   const GlobalRecordMap () const { return Globals; }
   const EnumRecordMap () const { return Enums; }
@@ -328,8 +328,8 @@ class APISet {
   /// \returns a StringRef of the copied string in APISet::Allocator.
   StringRef copyString(StringRef String);
 
-  APISet(const llvm::Triple , const LangOptions )
-  : Target(Target), LangOpts(LangOpts) {}
+  APISet(const llvm::Triple , Language Lang)
+  : Target(Target), Lang(Lang) {}
 
 private:
   /// BumpPtrAllocator to store generated/copied strings.
@@ -338,7 +338,7 @@ class APISet {
   llvm::BumpPtrAllocator StringAllocator;
 
   const llvm::Triple Target;
-  const LangOptions LangOpts;
+  const Language Lang;
 
   GlobalRecordMap Globals;
   EnumRecordMap Enums;

diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 0636e6de7cc26..dc3e067a837e2 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -41,9 +41,8 @@ namespace {
 /// information.
 class ExtractAPIVisitor : public RecursiveASTVisitor {
 public:
-  explicit ExtractAPIVisitor(ASTContext )
-  : Context(Context),
-API(Context.getTargetInfo().getTriple(), Context.getLangOpts()) {}
+  ExtractAPIVisitor(ASTContext , Language Lang)
+  : Context(Context), API(Context.getTargetInfo().getTriple(), Lang) {}
 
   const APISet () const { return API; }
 
@@ -309,9 +308,9 @@ class ExtractAPIVisitor : public 
RecursiveASTVisitor {
 
 class ExtractAPIConsumer : public ASTConsumer {
 public:
-  ExtractAPIConsumer(ASTContext , StringRef ProductName,
+  ExtractAPIConsumer(ASTContext , StringRef ProductName, Language Lang,
  std::unique_ptr OS)
-  : Visitor(Context), ProductName(ProductName), OS(std::move(OS)) {}
+  : Visitor(Context, Lang), ProductName(ProductName), OS(std::move(OS)) {}
 
   void HandleTranslationUnit(ASTContext ) override {
 // Use ExtractAPIVisitor to traverse symbol declarations in the context.
@@ -339,6 +338,7 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance , 
StringRef InFile) {
 return nullptr;
   return std::make_unique(
   CI.getASTContext(), CI.getInvocation().getFrontendOpts().ProductName,
+  CI.getFrontendOpts().Inputs.back().getKind().getLanguage(),
   std::move(OS));
 }
 

diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 54276f6cf1de1..cde81ecf0abd4 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -151,11 +151,9 @@ Optional serializeAvailability(const 
AvailabilityInfo ) {
   return Availbility;
 }
 
-/// Get the short language name string for interface language references.
-StringRef getLanguageName(const LangOptions ) {
-  auto LanguageKind =
-  LangStandard::getLangStandardForKind(LangOpts.LangStd).getLanguage();
-  switch (LanguageKind) {
+/// Get the language name string for interface language references.
+StringRef getLanguageName(Language Lang) {
+  switch (Lang) {
   case Language::C:
 return "c";
   case Language::ObjC:
@@ -185,11 +183,10 @@ StringRef getLanguageName(const LangOptions ) {
 ///
 /// The identifier property of a symbol contains the USR for precise and unique
 /// references, and the interface language name.
-Object serializeIdentifier(const APIRecord ,
-   

[clang] e5a7d27 - [NFC][clang][extract-api] Add missing virtual anchors

2022-03-24 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-24T14:30:14-07:00
New Revision: e5a7d272ab04aef47bf9ae5a34ca34878353197c

URL: 
https://github.com/llvm/llvm-project/commit/e5a7d272ab04aef47bf9ae5a34ca34878353197c
DIFF: 
https://github.com/llvm/llvm-project/commit/e5a7d272ab04aef47bf9ae5a34ca34878353197c.diff

LOG: [NFC][clang][extract-api] Add missing virtual anchors

Add missing virtual method anchors for structs in ExtractAPI/API.h

Added: 


Modified: 
clang/include/clang/ExtractAPI/API.h
clang/lib/ExtractAPI/API.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index beedda6464438..eb72450f87d23 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -142,6 +142,9 @@ struct EnumConstantRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_EnumConstant;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with enums.
@@ -157,6 +160,9 @@ struct EnumRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_Enum;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with struct fields.
@@ -171,6 +177,9 @@ struct StructFieldRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_StructField;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// This holds information associated with structs.
@@ -187,6 +196,9 @@ struct StructRecord : APIRecord {
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_Struct;
   }
+
+private:
+  virtual void anchor();
 };
 
 /// APISet holds the set of API records collected from given inputs.

diff  --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp
index 6b60d2c2a1b42..92c4e0ea48383 100644
--- a/clang/lib/ExtractAPI/API.cpp
+++ b/clang/lib/ExtractAPI/API.cpp
@@ -131,3 +131,7 @@ StringRef APISet::copyString(StringRef String) {
 APIRecord::~APIRecord() {}
 
 void GlobalRecord::anchor() {}
+void EnumConstantRecord::anchor() {}
+void EnumRecord::anchor() {}
+void StructFieldRecord::anchor() {}
+void StructRecord::anchor() {}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 826e661 - [NFC][clang][extract-api] Rename variable

2022-03-24 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-24T15:12:40-07:00
New Revision: 826e661a96a2aa7eb309dbca16c85a3d05edcec8

URL: 
https://github.com/llvm/llvm-project/commit/826e661a96a2aa7eb309dbca16c85a3d05edcec8
DIFF: 
https://github.com/llvm/llvm-project/commit/826e661a96a2aa7eb309dbca16c85a3d05edcec8.diff

LOG: [NFC][clang][extract-api] Rename variable

Rename a local variable name to avoid potential ambiguity/conflict for
some compilers.

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 57fcc8aa04d5b..af44fce0cbc97 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -153,9 +153,9 @@ Optional serializeAvailability(const 
AvailabilityInfo ) {
 
 /// Get the short language name string for interface language references.
 StringRef getLanguageName(const LangOptions ) {
-  auto Language =
+  auto LanguageKind =
   LangStandard::getLangStandardForKind(LangOpts.LangStd).getLanguage();
-  switch (Language) {
+  switch (LanguageKind) {
   case Language::C:
 return "c";
   case Language::ObjC:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b1d946c - [clang] Add an extract-api driver option

2022-01-26 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-01-26T11:31:12-08:00
New Revision: b1d946cbf780f1769b3a3a39ce68e462a181869e

URL: 
https://github.com/llvm/llvm-project/commit/b1d946cbf780f1769b3a3a39ce68e462a181869e
DIFF: 
https://github.com/llvm/llvm-project/commit/b1d946cbf780f1769b3a3a39ce68e462a181869e.diff

LOG: [clang] Add an extract-api driver option

This is the initial commit for the clang-extract-api RFC

Add a new driver option `-extract-api` and associate it with a dummy
(for now) frontend action to set up the initial structure for
incremental works.

Differential Revision: https://reviews.llvm.org/D117809

Added: 
clang/lib/Frontend/ExtractAPIConsumer.cpp
clang/test/Driver/extract-api.c

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/Types.def
clang/include/clang/Frontend/FrontendActions.h
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/Types.cpp
clang/lib/Frontend/CMakeLists.txt
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 49ceebcb51cf5..a57787a4f4c38 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1080,6 +1080,8 @@ def end_no_unused_arguments : Flag<["--"], 
"end-no-unused-arguments">, Flags<[Co
   HelpText<"Start emitting warnings for unused driver arguments">;
 def interface_stub_version_EQ : JoinedOrSeparate<["-"], 
"interface-stub-version=">, Flags<[CC1Option]>;
 def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
+def extract_api : Flag<["-"], "extract-api">, Flags<[CC1Option]>, 
Group,
+  HelpText<"Extract API information">;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, 
Flags<[CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,

diff  --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index 997eea445c225..7adf59ca5c992 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -100,4 +100,5 @@ TYPE("dSYM", dSYM, INVALID, 
"dSYM",   phases
 TYPE("dependencies", Dependencies, INVALID, "d",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("cuda-fatbin",  CUDA_FATBIN,  INVALID, "fatbin", 
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("hip-fatbin",   HIP_FATBIN,   INVALID, "hipfb",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("api-information",  API_INFO, INVALID, "json",   
phases::Compile)
 TYPE("none", Nothing,  INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)

diff  --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index 8bd6509559f70..8eceb81723d23 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
 
 #include "clang/Frontend/FrontendAction.h"
+#include 
 #include 
 #include 
 
@@ -270,6 +271,12 @@ class PrintDependencyDirectivesSourceMinimizerAction : 
public FrontendAction {
   bool usesPreprocessorOnly() const override { return true; }
 };
 
+class ExtractAPIAction : public ASTFrontendAction {
+protected:
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override;
+};
+
 
//===--===//
 // Preprocessor Actions
 
//===--===//

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 1d9d89a28c6c4..7ce8076a3ee41 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -75,6 +75,9 @@ enum ActionKind {
   /// Emit a .o file.
   EmitObj,
 
+  // Extract API information
+  ExtractAPI,
+
   /// Parse and apply any fixits to the source.
   FixIt,
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c7314e11c7865..2e4ebc10e9ba3 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -62,6 +62,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
+#include "clang/Driver/Types.h"
 #include "llvm/ADT/ArrayRef.h"
 

[clang] 98fa46f - [FIX][clang] Fix unused private field in ExtractAPIVisitor

2022-01-26 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-01-26T16:24:04-08:00
New Revision: 98fa46f870e402f225b60ab5d02487c36d79632b

URL: 
https://github.com/llvm/llvm-project/commit/98fa46f870e402f225b60ab5d02487c36d79632b
DIFF: 
https://github.com/llvm/llvm-project/commit/98fa46f870e402f225b60ab5d02487c36d79632b.diff

LOG: [FIX][clang] Fix unused private field in ExtractAPIVisitor

Fix a build failure where an unused private field in ExtractAPIVisitor
triggered a warning turned into error.

Added: 


Modified: 
clang/lib/Frontend/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ExtractAPIConsumer.cpp 
b/clang/lib/Frontend/ExtractAPIConsumer.cpp
index 92a0385c96cc0..cdf67f3c327aa 100644
--- a/clang/lib/Frontend/ExtractAPIConsumer.cpp
+++ b/clang/lib/Frontend/ExtractAPIConsumer.cpp
@@ -9,21 +9,14 @@ using namespace clang;
 namespace {
 class ExtractAPIVisitor : public RecursiveASTVisitor {
 public:
-  explicit ExtractAPIVisitor(ASTContext *Context) : Context(Context) {}
-
   bool VisitNamedDecl(NamedDecl *Decl) {
 llvm::outs() << Decl->getName() << "\n";
 return true;
   }
-
-private:
-  ASTContext *Context;
 };
 
 class ExtractAPIConsumer : public ASTConsumer {
 public:
-  explicit ExtractAPIConsumer(ASTContext *Context) : Visitor(Context) {}
-
   void HandleTranslationUnit(ASTContext ) override {
 Visitor.TraverseDecl(Context.getTranslationUnitDecl());
   }
@@ -35,5 +28,5 @@ class ExtractAPIConsumer : public ASTConsumer {
 
 std::unique_ptr
 ExtractAPIAction::CreateASTConsumer(CompilerInstance , StringRef InFile) {
-  return std::make_unique(());
+  return std::make_unique();
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e08c435 - [clang][ExtractAPI][NFC] Fix sed delimiter in test

2022-04-12 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-04-12T10:00:15-07:00
New Revision: e08c435401bc335c687b693591feafd7dbca1455

URL: 
https://github.com/llvm/llvm-project/commit/e08c435401bc335c687b693591feafd7dbca1455
DIFF: 
https://github.com/llvm/llvm-project/commit/e08c435401bc335c687b693591feafd7dbca1455.diff

LOG: [clang][ExtractAPI][NFC] Fix sed delimiter in test

Fix path replacement in sed (properly this time) using lit
regex_replacement.

Differential Revision: https://reviews.llvm.org/D123526

Co-authored-by: Michele Scandale 
Co-authored-by: Zixu Wang <9819235+zix...@users.noreply.github.com>

Added: 


Modified: 
clang/test/ExtractAPI/enum.c
clang/test/ExtractAPI/global_record.c
clang/test/ExtractAPI/global_record_multifile.c
clang/test/ExtractAPI/known_files_only.c
clang/test/ExtractAPI/known_files_only_hmap.c
clang/test/ExtractAPI/language.c
clang/test/ExtractAPI/macro_undefined.c
clang/test/ExtractAPI/macros.c
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_interface.m
clang/test/ExtractAPI/objc_protocol.m
clang/test/ExtractAPI/struct.c
clang/test/ExtractAPI/typedef.c
clang/test/ExtractAPI/typedef_anonymous_record.c
clang/test/ExtractAPI/typedef_chain.c

Removed: 




diff  --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c
index 60f69059c942f..49e39f7ba410a 100644
--- a/clang/test/ExtractAPI/enum.c
+++ b/clang/test/ExtractAPI/enum.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
-// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
 // RUN: %clang -extract-api -target arm64-apple-macosx \
 // RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
 

diff  --git a/clang/test/ExtractAPI/global_record.c 
b/clang/test/ExtractAPI/global_record.c
index 1722c03eb47f9..8516ac50be858 100644
--- a/clang/test/ExtractAPI/global_record.c
+++ b/clang/test/ExtractAPI/global_record.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
-// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
 // RUN: %clang -extract-api --product-name=GlobalRecord -target 
arm64-apple-macosx \
 // RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
 

diff  --git a/clang/test/ExtractAPI/global_record_multifile.c 
b/clang/test/ExtractAPI/global_record_multifile.c
index 4d6566506a226..0eacb8a94b77f 100644
--- a/clang/test/ExtractAPI/global_record_multifile.c
+++ b/clang/test/ExtractAPI/global_record_multifile.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
-// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
 // RUN: %clang -extract-api --product-name=GlobalRecord -target 
arm64-apple-macosx \
 // RUN: %t/input1.h %t/input2.h %t/input3.h -o %t/output.json | FileCheck 
-allow-empty %s
 

diff  --git a/clang/test/ExtractAPI/known_files_only.c 
b/clang/test/ExtractAPI/known_files_only.c
index 6baba4e7d921e..ddb6e577823a8 100644
--- a/clang/test/ExtractAPI/known_files_only.c
+++ b/clang/test/ExtractAPI/known_files_only.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
-// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
 // RUN: %clang -extract-api --product-name=GlobalRecord -target 
arm64-apple-macosx \
 // RUN: %t/input1.h -o %t/output.json | FileCheck -allow-empty %s
 

diff  --git a/clang/test/ExtractAPI/known_files_only_hmap.c 
b/clang/test/ExtractAPI/known_files_only_hmap.c
index d5d06e65aa6f9..3b7609a73b267 100644
--- a/clang/test/ExtractAPI/known_files_only_hmap.c
+++ b/clang/test/ExtractAPI/known_files_only_hmap.c
@@ -1,9 +1,9 @@
 // RUN: rm -rf %t
 // RUN: split-file %s %t
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
-// RUN: %t/reference.output.json
-// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/known_files_only.hmap.json.in >> \
-// RUN: %t/known_files_only.hmap.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/known_files_only.hmap.json.in >> %t/known_files_only.hmap.json
 // RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
 // RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target 
arm64-apple-macosx \
 // RUN: 

[clang] 4048aad - [clang][ExtractAPI] Fix declaration fragments for ObjC methods

2022-04-07 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-04-07T10:22:41-07:00
New Revision: 4048aad85a843d2b15cb8e60b2ea37f148b7b770

URL: 
https://github.com/llvm/llvm-project/commit/4048aad85a843d2b15cb8e60b2ea37f148b7b770
DIFF: 
https://github.com/llvm/llvm-project/commit/4048aad85a843d2b15cb8e60b2ea37f148b7b770.diff

LOG: [clang][ExtractAPI] Fix declaration fragments for ObjC methods

Objective-C methods selector parts should be considered as identifiers.

Depends on D123259

Differential Revision: https://reviews.llvm.org/D123261

Added: 


Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_interface.m

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index a569ff9168bc3..75d360a3ba167 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -593,20 +593,21 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForObjCMethod(
 
   // For Objective-C methods that take arguments, build the selector slots.
   for (unsigned i = 0, end = Method->param_size(); i != end; ++i) {
-Fragments.appendSpace()
-.append(Selector.getNameForSlot(i),
-// The first slot is the name of the method, record as an
-// identifier, otherwise as exteranl parameters.
-i == 0 ? DeclarationFragments::FragmentKind::Identifier
-   : DeclarationFragments::FragmentKind::ExternalParam)
-.append(":", DeclarationFragments::FragmentKind::Text);
+// Objective-C method selector parts are considered as identifiers instead
+// of "external parameters" as in Swift. This is because Objective-C method
+// symbols are referenced with the entire selector, instead of just the
+// method name in Swift.
+SmallString<32> ParamID(Selector.getNameForSlot(i));
+ParamID.append(":");
+Fragments.appendSpace().append(
+ParamID, DeclarationFragments::FragmentKind::Identifier);
 
 // Build the internal parameter.
 const ParmVarDecl *Param = Method->getParamDecl(i);
 Fragments.append(getFragmentsForParam(Param));
   }
 
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCProperty(

diff  --git a/clang/test/ExtractAPI/objc_category.m 
b/clang/test/ExtractAPI/objc_category.m
index 2416e3049bd55..20eefdfbb00e5 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -136,6 +136,10 @@ + (void)ClassMethod;
 {
   "kind": "identifier",
   "spelling": "InstanceMethod"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -190,6 +194,10 @@ + (void)ClassMethod;
 {
   "kind": "identifier",
   "spelling": "ClassMethod"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {

diff  --git a/clang/test/ExtractAPI/objc_interface.m 
b/clang/test/ExtractAPI/objc_interface.m
index a74a53c8db2cf..5ca6404683987 100644
--- a/clang/test/ExtractAPI/objc_interface.m
+++ b/clang/test/ExtractAPI/objc_interface.m
@@ -146,11 +146,7 @@ - (char)getIvar;
 },
 {
   "kind": "identifier",
-  "spelling": "getWithProperty"
-},
-{
-  "kind": "text",
-  "spelling": ":"
+  "spelling": "getWithProperty:"
 },
 {
   "kind": "text",
@@ -168,6 +164,10 @@ - (char)getIvar;
 {
   "kind": "internalParam",
   "spelling": "Property"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -403,6 +403,10 @@ - (char)getIvar;
 {
   "kind": "identifier",
   "spelling": "getIvar"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fe2c77a - [clang][ExtractAPI] Fix appendSpace in DeclarationFragments

2022-04-07 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-04-07T09:17:30-07:00
New Revision: fe2c77a0065cda43418d625f0162a974ce8ec1e5

URL: 
https://github.com/llvm/llvm-project/commit/fe2c77a0065cda43418d625f0162a974ce8ec1e5
DIFF: 
https://github.com/llvm/llvm-project/commit/fe2c77a0065cda43418d625f0162a974ce8ec1e5.diff

LOG: [clang][ExtractAPI] Fix appendSpace in DeclarationFragments

There is a bug in `DeclarationFragments::appendSpace` where the space
character is added to a local copy of the last fragment.

Differential Revision: https://reviews.llvm.org/D123259

Added: 


Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/test/ExtractAPI/global_record.c
clang/test/ExtractAPI/global_record_multifile.c
clang/test/ExtractAPI/macro_undefined.c
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_interface.m

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index fa28fad358db9..a569ff9168bc3 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -21,7 +21,7 @@ using namespace llvm;
 
 DeclarationFragments ::appendSpace() {
   if (!Fragments.empty()) {
-Fragment Last = Fragments.back();
+Fragment  = Fragments.back();
 if (Last.Kind == FragmentKind::Text) {
   // Merge the extra space into the last fragment if the last fragment is
   // also text.
@@ -390,7 +390,7 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const 
ParmVarDecl *Param) {
   if (Param->isObjCMethodParameter())
 Fragments.append("(", DeclarationFragments::FragmentKind::Text)
 .append(std::move(TypeFragments))
-.append(")", DeclarationFragments::FragmentKind::Text);
+.append(") ", DeclarationFragments::FragmentKind::Text);
   else
 Fragments.append(std::move(TypeFragments)).appendSpace();
 

diff  --git a/clang/test/ExtractAPI/global_record.c 
b/clang/test/ExtractAPI/global_record.c
index 4c14cae2de877..dfe99c2f55f67 100644
--- a/clang/test/ExtractAPI/global_record.c
+++ b/clang/test/ExtractAPI/global_record.c
@@ -175,7 +175,7 @@ char unavailable __attribute__((unavailable));
 },
 {
   "kind": "text",
-  "spelling": " *"
+  "spelling": " * "
 },
 {
   "kind": "internalParam",
@@ -331,7 +331,7 @@ char unavailable __attribute__((unavailable));
   },
   {
 "kind": "text",
-"spelling": " *"
+"spelling": " * "
   },
   {
 "kind": "internalParam",

diff  --git a/clang/test/ExtractAPI/global_record_multifile.c 
b/clang/test/ExtractAPI/global_record_multifile.c
index 76e18811a53b4..577eb121cf922 100644
--- a/clang/test/ExtractAPI/global_record_multifile.c
+++ b/clang/test/ExtractAPI/global_record_multifile.c
@@ -177,7 +177,7 @@ char unavailable __attribute__((unavailable));
 },
 {
   "kind": "text",
-  "spelling": " *"
+  "spelling": " * "
 },
 {
   "kind": "internalParam",
@@ -333,7 +333,7 @@ char unavailable __attribute__((unavailable));
   },
   {
 "kind": "text",
-"spelling": " *"
+"spelling": " * "
   },
   {
 "kind": "internalParam",

diff  --git a/clang/test/ExtractAPI/macro_undefined.c 
b/clang/test/ExtractAPI/macro_undefined.c
index feb4b3f43637e..0ae04d02e1543 100644
--- a/clang/test/ExtractAPI/macro_undefined.c
+++ b/clang/test/ExtractAPI/macro_undefined.c
@@ -142,7 +142,7 @@ FUNC_GEN(bar, const int *, unsigned);
 },
 {
   "kind": "text",
-  "spelling": " *"
+  "spelling": " * "
 },
 {
   "kind": "internalParam",
@@ -189,7 +189,7 @@ FUNC_GEN(bar, const int *, unsigned);
   },
   {
 "kind": "text",
-"spelling": " *"
+"spelling": " * "
   },
   {
 "kind": "internalParam",

diff  --git a/clang/test/ExtractAPI/objc_category.m 
b/clang/test/ExtractAPI/objc_category.m
index bc572adfcd161..2416e3049bd55 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -131,7 +131,7 @@ + (void)ClassMethod;
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ") "
 },
 {
   "kind": "identifier",
@@ -185,7 +185,7 @@ + (void)ClassMethod;
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ") "
 },
 {
   "kind": "identifier",
@@ -266,7 +266,7 @@ + (void)ClassMethod;
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ") 

[clang] 178aad9 - [clang][extract-api] Add Objective-C Category support

2022-04-06 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-04-06T12:00:12-07:00
New Revision: 178aad9b946e3c5abe9df162e5c482fb4acae99c

URL: 
https://github.com/llvm/llvm-project/commit/178aad9b946e3c5abe9df162e5c482fb4acae99c
DIFF: 
https://github.com/llvm/llvm-project/commit/178aad9b946e3c5abe9df162e5c482fb4acae99c.diff

LOG: [clang][extract-api] Add Objective-C Category support

Add (partial) support for Objective-C category records in ExtractAPI.
The current ExtractAPI collects everything for an Objective-C category,
but not fully serialized in the SymbolGraphSerializer. Categories
extending external interfaces are disgarded during serialization, and
categories extending known interfaces are merged (all members surfaced)
into the interfaces.

Differential Revision: https://reviews.llvm.org/D122774

Added: 
clang/test/ExtractAPI/objc_category.m

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 827cde953c31c..57b6a2ee5a43c 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -86,6 +86,7 @@ struct APIRecord {
 RK_ObjCIvar,
 RK_ObjCMethod,
 RK_ObjCInterface,
+RK_ObjCCategory,
 RK_ObjCProtocol,
 RK_MacroDefinition,
 RK_Typedef,
@@ -340,9 +341,33 @@ struct ObjCContainerRecord : APIRecord {
   virtual ~ObjCContainerRecord() = 0;
 };
 
+/// This holds information associated with Objective-C categories.
+struct ObjCCategoryRecord : ObjCContainerRecord {
+  SymbolReference Interface;
+
+  ObjCCategoryRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
+ const AvailabilityInfo ,
+ const DocComment ,
+ DeclarationFragments Declaration,
+ DeclarationFragments SubHeading, SymbolReference 
Interface)
+  : ObjCContainerRecord(RK_ObjCCategory, Name, USR, Loc, Availability,
+LinkageInfo::none(), Comment, Declaration,
+SubHeading),
+Interface(Interface) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_ObjCCategory;
+  }
+
+private:
+  virtual void anchor();
+};
+
 /// This holds information associated with Objective-C interfaces/classes.
 struct ObjCInterfaceRecord : ObjCContainerRecord {
   SymbolReference SuperClass;
+  // ObjCCategoryRecord%s are stored in and owned by APISet.
+  SmallVector Categories;
 
   ObjCInterfaceRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
   const AvailabilityInfo , LinkageInfo 
Linkage,
@@ -512,6 +537,18 @@ class APISet {
   DeclarationFragments Declaration,
   DeclarationFragments SubHeading);
 
+  /// Create and add an Objective-C category record into the API set.
+  ///
+  /// Note: the caller is responsible for keeping the StringRef \p Name and
+  /// \p USR alive. APISet::copyString provides a way to copy strings into
+  /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
+  /// to generate the USR for \c D and keep it alive in APISet.
+  ObjCCategoryRecord *
+  addObjCCategory(StringRef Name, StringRef USR, PresumedLoc Loc,
+  const AvailabilityInfo ,
+  const DocComment , DeclarationFragments Declaration,
+  DeclarationFragments SubHeading, SymbolReference Interface);
+
   /// Create and add an Objective-C interface record into the API set.
   ///
   /// Note: the caller is responsible for keeping the StringRef \p Name and
@@ -618,6 +655,9 @@ class APISet {
   const RecordMap () const { return Globals; }
   const RecordMap () const { return Enums; }
   const RecordMap () const { return Structs; }
+  const RecordMap () const {
+return ObjCCategories;
+  }
   const RecordMap () const {
 return ObjCInterfaces;
   }
@@ -662,6 +702,7 @@ class APISet {
   RecordMap Globals;
   RecordMap Enums;
   RecordMap Structs;
+  RecordMap ObjCCategories;
   RecordMap ObjCInterfaces;
   RecordMap ObjCProtocols;
   RecordMap Macros;

diff  --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h 
b/clang/include/clang/ExtractAPI/DeclarationFragments.h
index 80fb5faf68783..55a6768eed9b9 100644
--- a/clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -204,6 +204,11 @@ class DeclarationFragmentsBuilder {
   /// Build DeclarationFragments for a struct record declaration RecordDecl.
   static DeclarationFragments 

[clang] [clang][ExtractAPI] Update availability serialization in SGF (PR #71418)

2023-11-06 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/71418
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 54b145d - [NFC] Disable clang/SymbolGraph test

2022-03-17 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-17T10:14:19-07:00
New Revision: 54b145d5cac2b008380828e8f67c439038ea370b

URL: 
https://github.com/llvm/llvm-project/commit/54b145d5cac2b008380828e8f67c439038ea370b
DIFF: 
https://github.com/llvm/llvm-project/commit/54b145d5cac2b008380828e8f67c439038ea370b.diff

LOG: [NFC] Disable clang/SymbolGraph test

Added: 


Modified: 
clang/test/SymbolGraph/global_record.c

Removed: 




diff  --git a/clang/test/SymbolGraph/global_record.c 
b/clang/test/SymbolGraph/global_record.c
index fa577ee29b17d..c1baaf260fd10 100644
--- a/clang/test/SymbolGraph/global_record.c
+++ b/clang/test/SymbolGraph/global_record.c
@@ -1,3 +1,5 @@
+// FIXME: disable the test to unblock build bots
+// UNSUPPORTED: true
 // RUN: rm -rf %t
 // RUN: split-file %s %t
 // RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5f841c7 - [NFC] Remove unfinished test case

2022-05-04 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-05-04T10:40:25-07:00
New Revision: 5f841c71fc2cc77c92f526791cd7a938bcac69aa

URL: 
https://github.com/llvm/llvm-project/commit/5f841c71fc2cc77c92f526791cd7a938bcac69aa
DIFF: 
https://github.com/llvm/llvm-project/commit/5f841c71fc2cc77c92f526791cd7a938bcac69aa.diff

LOG: [NFC] Remove unfinished test case

4c262fee08b5383c96857d77eefe80d61c41d2b0 accidentally added local
unfinished test case clang/test/Index/annotate-comments-enum-constant.c
This patch removes it.

Added: 


Modified: 


Removed: 
clang/test/Index/annotate-comments-enum-constant.c



diff  --git a/clang/test/Index/annotate-comments-enum-constant.c 
b/clang/test/Index/annotate-comments-enum-constant.c
deleted file mode 100644
index f86eaf4742d30..0
--- a/clang/test/Index/annotate-comments-enum-constant.c
+++ /dev/null
@@ -1,17 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: c-index-test -test-load-source all 
-comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s > %t/out
-// RUN: FileCheck %s --dump-input always < %t/out
-
-enum {
-  /// Documentation for Foo
-  Foo,
-  Bar, // No documentation for Bar
-  /// Documentation for Baz
-  Baz,
-};
-// CHECK: EnumConstantDecl=Foo:[[@LINE-5]]:3 (Definition) {{.*}} 
BriefComment=[Documentation for Foo] FullCommentAsHTML=[ 
Documentation for Foo] FullCommentAsXML=[Fooc:@Ea@Foo@FooFoo
 Documentation for Foo]
-// CHECK: EnumConstantDecl=Bar:[[@LINE-5]]:3 (Definition)
-// CHECK-NOT: BriefComment=[Documentation for Foo]
-// CHECK: EnumConstantDecl=Baz:[[@LINE-5]]:3 (Definition) {{.*}} 
BriefComment=[Documentation for Baz] FullCommentAsHTML=[ 
Documentation for Baz] FullCommentAsXML=[Bazc:@Ea@Foo@BazBaz
 Documentation for Baz]
-



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2966f0f - Revert "[clang][extract-api] Use relative includes"

2022-05-04 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-05-04T12:27:20-07:00
New Revision: 2966f0fa505266735dbc8324b8821b7f0aa901ff

URL: 
https://github.com/llvm/llvm-project/commit/2966f0fa505266735dbc8324b8821b7f0aa901ff
DIFF: 
https://github.com/llvm/llvm-project/commit/2966f0fa505266735dbc8324b8821b7f0aa901ff.diff

LOG: Revert "[clang][extract-api] Use relative includes"

This reverts commit 4c262fee08b5383c96857d77eefe80d61c41d2b0.
Revert to fix Msan and Asan errors.

Added: 
clang/test/ExtractAPI/known_files_only_hmap.c

Modified: 
clang/include/clang/ExtractAPI/FrontendActions.h
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 
clang/test/ExtractAPI/relative_include.m



diff  --git a/clang/include/clang/ExtractAPI/FrontendActions.h 
b/clang/include/clang/ExtractAPI/FrontendActions.h
index 2cb8ef130fdd7..dec3b5ca93d18 100644
--- a/clang/include/clang/ExtractAPI/FrontendActions.h
+++ b/clang/include/clang/ExtractAPI/FrontendActions.h
@@ -40,10 +40,7 @@ class ExtractAPIAction : public ASTFrontendAction {
   std::unique_ptr Buffer;
 
   /// The input file originally provided on the command line.
-  ///
-  /// This captures the spelling used to include the file and whether the
-  /// include is quoted or not.
-  SmallVector, bool>> KnownInputFiles;
+  std::vector KnownInputFiles;
 
   /// Prepare to execute the action on the given CompilerInstance.
   ///

diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 317bcd1be8256..b1de2674b622b 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -38,10 +38,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/Regex.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -58,128 +55,10 @@ StringRef getTypedefName(const TagDecl *Decl) {
   return {};
 }
 
-Optional getRelativeIncludeName(const CompilerInstance ,
- StringRef File,
- bool *IsQuoted = nullptr) {
-  assert(CI.hasFileManager() &&
- "CompilerInstance does not have a FileNamager!");
-
-  using namespace llvm::sys;
-  // Matches framework include patterns
-  const llvm::Regex Rule("/(.+)\\.framework/(.+)?Headers/(.+)");
-
-  const auto  = CI.getVirtualFileSystem();
-
-  SmallString<128> FilePath(File.begin(), File.end());
-  FS.makeAbsolute(FilePath);
-  path::remove_dots(FilePath, true);
-  File = FilePath;
-
-  // Checks whether `Dir` is a strict path prefix of `File`. If so returns
-  // the prefix length. Otherwise return 0.
-  auto CheckDir = [&](llvm::StringRef Dir) -> unsigned {
-llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
-FS.makeAbsolute(DirPath);
-path::remove_dots(DirPath, true);
-Dir = DirPath;
-for (auto NI = path::begin(File), NE = path::end(File),
-  DI = path::begin(Dir), DE = path::end(Dir);
- /*termination condition in loop*/; ++NI, ++DI) {
-  // '.' components in File are ignored.
-  while (NI != NE && *NI == ".")
-++NI;
-  if (NI == NE)
-break;
-
-  // '.' components in Dir are ignored.
-  while (DI != DE && *DI == ".")
-++DI;
-
-  // Dir is a prefix of File, up to '.' components and choice of path
-  // separators.
-  if (DI == DE)
-return NI - path::begin(File);
-
-  // Consider all path separators equal.
-  if (NI->size() == 1 && DI->size() == 1 &&
-  path::is_separator(NI->front()) && path::is_separator(DI->front()))
-continue;
-
-  // Special case Apple .sdk folders since the search path is typically a
-  // symlink like `iPhoneSimulator14.5.sdk` while the file is instead
-  // located in `iPhoneSimulator.sdk` (the real folder).
-  if (NI->endswith(".sdk") && DI->endswith(".sdk")) {
-StringRef NBasename = path::stem(*NI);
-StringRef DBasename = path::stem(*DI);
-if (DBasename.startswith(NBasename))
-  continue;
-  }
-
-  if (*NI != *DI)
-break;
-}
-return 0;
-  };
-
-  unsigned PrefixLength = 0;
-
-  // Go through the search paths and find the first one that is a prefix of
-  // the header.
-  for (const auto  : CI.getHeaderSearchOpts().UserEntries) {
-// Note whether the match is found in a quoted entry.
-if (IsQuoted)
-  *IsQuoted = Entry.Group == frontend::Quoted;
-
-if (auto EntryFile = CI.getFileManager().getOptionalFileRef(Entry.Path)) {
-  if (auto HMap = HeaderMap::Create(*EntryFile, CI.getFileManager())) {
-// If this is a headermap entry, try to reverse lookup the full path
-// for a spelled name before mapping.
-StringRef SpelledFilename =
-   

[clang] 4c262fe - [clang][extract-api] Use relative includes

2022-05-04 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-05-04T10:28:01-07:00
New Revision: 4c262fee08b5383c96857d77eefe80d61c41d2b0

URL: 
https://github.com/llvm/llvm-project/commit/4c262fee08b5383c96857d77eefe80d61c41d2b0
DIFF: 
https://github.com/llvm/llvm-project/commit/4c262fee08b5383c96857d77eefe80d61c41d2b0.diff

LOG: [clang][extract-api] Use relative includes

This patch transforms the given input headers to relative include names
using header search entries and some heuritics.
For example: `/Path/To/Header.h` will be included as `` with a
search path of `-I /Path/To/`; and
`/Path/To/Framework.framework/Headers/Header.h` will be included as
``, given a search path of `-F /Path/To`.
Headermaps will also be queried in reverse to find a spelled name to
include headers.

Differential Revision: https://reviews.llvm.org/D123831

Added: 
clang/test/ExtractAPI/relative_include.m
clang/test/Index/annotate-comments-enum-constant.c

Modified: 
clang/include/clang/ExtractAPI/FrontendActions.h
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 
clang/test/ExtractAPI/known_files_only_hmap.c



diff  --git a/clang/include/clang/ExtractAPI/FrontendActions.h 
b/clang/include/clang/ExtractAPI/FrontendActions.h
index dec3b5ca93d18..2cb8ef130fdd7 100644
--- a/clang/include/clang/ExtractAPI/FrontendActions.h
+++ b/clang/include/clang/ExtractAPI/FrontendActions.h
@@ -40,7 +40,10 @@ class ExtractAPIAction : public ASTFrontendAction {
   std::unique_ptr Buffer;
 
   /// The input file originally provided on the command line.
-  std::vector KnownInputFiles;
+  ///
+  /// This captures the spelling used to include the file and whether the
+  /// include is quoted or not.
+  SmallVector, bool>> KnownInputFiles;
 
   /// Prepare to execute the action on the given CompilerInstance.
   ///

diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index b1de2674b622b..317bcd1be8256 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -38,7 +38,10 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -55,10 +58,128 @@ StringRef getTypedefName(const TagDecl *Decl) {
   return {};
 }
 
+Optional getRelativeIncludeName(const CompilerInstance ,
+ StringRef File,
+ bool *IsQuoted = nullptr) {
+  assert(CI.hasFileManager() &&
+ "CompilerInstance does not have a FileNamager!");
+
+  using namespace llvm::sys;
+  // Matches framework include patterns
+  const llvm::Regex Rule("/(.+)\\.framework/(.+)?Headers/(.+)");
+
+  const auto  = CI.getVirtualFileSystem();
+
+  SmallString<128> FilePath(File.begin(), File.end());
+  FS.makeAbsolute(FilePath);
+  path::remove_dots(FilePath, true);
+  File = FilePath;
+
+  // Checks whether `Dir` is a strict path prefix of `File`. If so returns
+  // the prefix length. Otherwise return 0.
+  auto CheckDir = [&](llvm::StringRef Dir) -> unsigned {
+llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
+FS.makeAbsolute(DirPath);
+path::remove_dots(DirPath, true);
+Dir = DirPath;
+for (auto NI = path::begin(File), NE = path::end(File),
+  DI = path::begin(Dir), DE = path::end(Dir);
+ /*termination condition in loop*/; ++NI, ++DI) {
+  // '.' components in File are ignored.
+  while (NI != NE && *NI == ".")
+++NI;
+  if (NI == NE)
+break;
+
+  // '.' components in Dir are ignored.
+  while (DI != DE && *DI == ".")
+++DI;
+
+  // Dir is a prefix of File, up to '.' components and choice of path
+  // separators.
+  if (DI == DE)
+return NI - path::begin(File);
+
+  // Consider all path separators equal.
+  if (NI->size() == 1 && DI->size() == 1 &&
+  path::is_separator(NI->front()) && path::is_separator(DI->front()))
+continue;
+
+  // Special case Apple .sdk folders since the search path is typically a
+  // symlink like `iPhoneSimulator14.5.sdk` while the file is instead
+  // located in `iPhoneSimulator.sdk` (the real folder).
+  if (NI->endswith(".sdk") && DI->endswith(".sdk")) {
+StringRef NBasename = path::stem(*NI);
+StringRef DBasename = path::stem(*DI);
+if (DBasename.startswith(NBasename))
+  continue;
+  }
+
+  if (*NI != *DI)
+break;
+}
+return 0;
+  };
+
+  unsigned PrefixLength = 0;
+
+  // Go through the search paths and find the first one that is a prefix of
+  // the header.
+  for (const auto  : CI.getHeaderSearchOpts().UserEntries) {
+// Note whether the match is 

[clang] cb5bb28 - Revert "Revert "[clang][extract-api] Use relative includes""

2022-05-04 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-05-04T14:52:45-07:00
New Revision: cb5bb28511f2c7530806af7ef53696deed453ca1

URL: 
https://github.com/llvm/llvm-project/commit/cb5bb28511f2c7530806af7ef53696deed453ca1
DIFF: 
https://github.com/llvm/llvm-project/commit/cb5bb28511f2c7530806af7ef53696deed453ca1.diff

LOG: Revert "Revert "[clang][extract-api] Use relative includes""

Reapply the change after fixing sanitizer errors.
The original problem was that `StringRef`s in `Matches` are pointing to
temporary local `std::string`s created by `path::convert_to_slash` in
the regex match call. This patch does the conversion up front in
container `FilePath`.

This reverts commit 2966f0fa505266735dbc8324b8821b7f0aa901ff.

Differential Revision: https://reviews.llvm.org/D124964

Added: 
clang/test/ExtractAPI/relative_include.m

Modified: 
clang/include/clang/ExtractAPI/FrontendActions.h
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 
clang/test/ExtractAPI/known_files_only_hmap.c



diff  --git a/clang/include/clang/ExtractAPI/FrontendActions.h 
b/clang/include/clang/ExtractAPI/FrontendActions.h
index dec3b5ca93d18d..2cb8ef130fdd77 100644
--- a/clang/include/clang/ExtractAPI/FrontendActions.h
+++ b/clang/include/clang/ExtractAPI/FrontendActions.h
@@ -40,7 +40,10 @@ class ExtractAPIAction : public ASTFrontendAction {
   std::unique_ptr Buffer;
 
   /// The input file originally provided on the command line.
-  std::vector KnownInputFiles;
+  ///
+  /// This captures the spelling used to include the file and whether the
+  /// include is quoted or not.
+  SmallVector, bool>> KnownInputFiles;
 
   /// Prepare to execute the action on the given CompilerInstance.
   ///

diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index b1de2674b622b1..70c8bac59ce978 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -38,7 +38,10 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -55,10 +58,125 @@ StringRef getTypedefName(const TagDecl *Decl) {
   return {};
 }
 
+Optional getRelativeIncludeName(const CompilerInstance ,
+ StringRef File,
+ bool *IsQuoted = nullptr) {
+  assert(CI.hasFileManager() &&
+ "CompilerInstance does not have a FileNamager!");
+
+  using namespace llvm::sys;
+  // Matches framework include patterns
+  const llvm::Regex Rule("/(.+)\\.framework/(.+)?Headers/(.+)");
+
+  const auto  = CI.getVirtualFileSystem();
+
+  SmallString<128> FilePath(File.begin(), File.end());
+  FS.makeAbsolute(FilePath);
+  path::remove_dots(FilePath, true);
+  FilePath = path::convert_to_slash(FilePath);
+  File = FilePath;
+
+  // Checks whether `Dir` is a strict path prefix of `File`. If so returns
+  // the prefix length. Otherwise return 0.
+  auto CheckDir = [&](llvm::StringRef Dir) -> unsigned {
+llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
+FS.makeAbsolute(DirPath);
+path::remove_dots(DirPath, true);
+Dir = DirPath;
+for (auto NI = path::begin(File), NE = path::end(File),
+  DI = path::begin(Dir), DE = path::end(Dir);
+ /*termination condition in loop*/; ++NI, ++DI) {
+  // '.' components in File are ignored.
+  while (NI != NE && *NI == ".")
+++NI;
+  if (NI == NE)
+break;
+
+  // '.' components in Dir are ignored.
+  while (DI != DE && *DI == ".")
+++DI;
+
+  // Dir is a prefix of File, up to '.' components and choice of path
+  // separators.
+  if (DI == DE)
+return NI - path::begin(File);
+
+  // Consider all path separators equal.
+  if (NI->size() == 1 && DI->size() == 1 &&
+  path::is_separator(NI->front()) && path::is_separator(DI->front()))
+continue;
+
+  // Special case Apple .sdk folders since the search path is typically a
+  // symlink like `iPhoneSimulator14.5.sdk` while the file is instead
+  // located in `iPhoneSimulator.sdk` (the real folder).
+  if (NI->endswith(".sdk") && DI->endswith(".sdk")) {
+StringRef NBasename = path::stem(*NI);
+StringRef DBasename = path::stem(*DI);
+if (DBasename.startswith(NBasename))
+  continue;
+  }
+
+  if (*NI != *DI)
+break;
+}
+return 0;
+  };
+
+  unsigned PrefixLength = 0;
+
+  // Go through the search paths and find the first one that is a prefix of
+  // the header.
+  for (const auto  : CI.getHeaderSearchOpts().UserEntries) {
+// Note whether the match is found in a quoted entry.
+if (IsQuoted)
+  

[clang] 5301826 - [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-10-05T13:11:21-07:00
New Revision: 5301826fa86aa520b65c86abbe3b3a7194849e27

URL: 
https://github.com/llvm/llvm-project/commit/5301826fa86aa520b65c86abbe3b3a7194849e27
DIFF: 
https://github.com/llvm/llvm-project/commit/5301826fa86aa520b65c86abbe3b3a7194849e27.diff

LOG: [clang][ExtractAPI] Don't print locations for anonymous tags

ExtractAPI doesn't care about locations of anonymous TagDecls. Set the
printing policy to exclude that from anonymous decl names.

Differential Revision: https://reviews.llvm.org/D135295

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 969ee772fa063..4a97ee9922ddd 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance , 
StringRef InFile) {
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 32b53cf - [ExtractAPI] Remove extra attributes in property declaration fragments

2023-04-04 Thread Zixu Wang via cfe-commits

Author: Usman Akinyemi
Date: 2023-04-04T10:00:34-07:00
New Revision: 32b53cf9d0c8c0e01ce5b0e7d5c717202a98cdf5

URL: 
https://github.com/llvm/llvm-project/commit/32b53cf9d0c8c0e01ce5b0e7d5c717202a98cdf5
DIFF: 
https://github.com/llvm/llvm-project/commit/32b53cf9d0c8c0e01ce5b0e7d5c717202a98cdf5.diff

LOG: [ExtractAPI] Remove extra attributes in property declaration fragments

Use `getPropertyAttributesAsWritten` instead of `getPropertyAttributes`
to get property attributes actually specified in the source code.
Resolves issue #61478.

https://reviews.llvm.org/D146759

Reviewed By: zixuw, dang

Differential Revision: https://reviews.llvm.org/D146759

Added: 


Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_id_protocol.m
clang/test/ExtractAPI/objc_interface.m
clang/test/ExtractAPI/objc_property.m

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 912e58a0c6e82..da75a701b405e 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -638,7 +638,7 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForObjCProperty(
   // Build the Objective-C property keyword.
   Fragments.append("@property", DeclarationFragments::FragmentKind::Keyword);
 
-  const auto Attributes = Property->getPropertyAttributes();
+  const auto Attributes = Property->getPropertyAttributesAsWritten();
   // Build the attributes if there is any associated with the property.
   if (Attributes != ObjCPropertyAttribute::kind_noattr) {
 // No leading comma for the first attribute.

diff  --git a/clang/test/ExtractAPI/objc_category.m 
b/clang/test/ExtractAPI/objc_category.m
index 185016dfe848c..3323d75f40392 100644
--- a/clang/test/ExtractAPI/objc_category.m
+++ b/clang/test/ExtractAPI/objc_category.m
@@ -282,39 +282,7 @@ + (void)ClassMethod;
 },
 {
   "kind": "text",
-  "spelling": " ("
-},
-{
-  "kind": "keyword",
-  "spelling": "atomic"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
-{
-  "kind": "keyword",
-  "spelling": "assign"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
-{
-  "kind": "keyword",
-  "spelling": "unsafe_unretained"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
-{
-  "kind": "keyword",
-  "spelling": "readwrite"
-},
-{
-  "kind": "text",
-  "spelling": ") "
+  "spelling": " "
 },
 {
   "kind": "typeIdentifier",

diff  --git a/clang/test/ExtractAPI/objc_id_protocol.m 
b/clang/test/ExtractAPI/objc_id_protocol.m
index 551e908ae4fdd..02f4cde772d48 100644
--- a/clang/test/ExtractAPI/objc_id_protocol.m
+++ b/clang/test/ExtractAPI/objc_id_protocol.m
@@ -122,14 +122,6 @@ @interface MyInterface
   "kind": "text",
   "spelling": " ("
 },
-{
-  "kind": "keyword",
-  "spelling": "atomic"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
 {
   "kind": "keyword",
   "spelling": "copy"
@@ -206,30 +198,6 @@ @interface MyInterface
   "kind": "text",
   "spelling": " ("
 },
-{
-  "kind": "keyword",
-  "spelling": "atomic"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
-{
-  "kind": "keyword",
-  "spelling": "assign"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
-{
-  "kind": "keyword",
-  "spelling": "unsafe_unretained"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
 {
   "kind": "keyword",
   "spelling": "readwrite"

diff  --git a/clang/test/ExtractAPI/objc_interface.m 
b/clang/test/ExtractAPI/objc_interface.m
index 159e97a193a13..3f53546866513 100644
--- a/clang/test/ExtractAPI/objc_interface.m
+++ b/clang/test/ExtractAPI/objc_interface.m
@@ -432,14 +432,6 @@ - (char)getIvar;
   "kind": "text",
   "spelling": " ("
 },
-{
-  "kind": "keyword",
-  "spelling": "atomic"
-},
-{
-  "kind": "text",
-  "spelling": ", "
-},
 {
   "kind": "keyword",
   "spelling": "readonly"

diff  --git a/clang/test/ExtractAPI/objc_property.m 
b/clang/test/ExtractAPI/objc_property.m
index f09a5ad724238..9c69a1156bffd 100644
--- a/clang/test/ExtractAPI/objc_property.m
+++ b/clang/test/ExtractAPI/objc_property.m
@@ -161,38 +161,6 @@ @interface 

[clang] Revert "[Docs] Add release note about Clang-defined target OS macros … (PR #80045)

2024-02-21 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w updated 
https://github.com/llvm/llvm-project/pull/80045

>From a38fe65d4ae26bae827d66009ae57236de597055 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Tue, 30 Jan 2024 10:44:21 -0800
Subject: [PATCH] Revert "[Docs] Add release note about Clang-defined target OS
 macros (#79879)"

This reverts commit b40d5b1b08564d23d5e0769892ebbc32447b2987.

The target OS macros work is included in the 18.x release. Move the
release note to the release branch.
---
 clang/docs/ReleaseNotes.rst | 26 --
 1 file changed, 26 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ef2d9b8e46ae4e..bac166e6c35627 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -62,21 +62,6 @@ Clang Frontend Potentially Breaking Changes
   of ``-Wno-gnu-binary-literal`` will no longer silence this pedantic warning,
   which may break existing uses with ``-Werror``.
 
-Target OS macros extension
-^^
-A new Clang extension (see :ref:`here `) is enabled for
-Darwin (Apple platform) targets. Clang now defines ``TARGET_OS_*`` macros for
-these targets, which could break existing code bases with improper checks for
-the ``TARGET_OS_`` macros. For example, existing checks might fail to include
-the ``TargetConditionals.h`` header from Apple SDKs and therefore leaving the
-macros undefined and guarded code unexercised.
-
-Affected code should be checked to see if it's still intended for the specific
-target and fixed accordingly.
-
-The extension can be turned off by the option ``-fno-define-target-os-macros``
-as a workaround.
-
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -161,17 +146,6 @@ Non-comprehensive list of changes in this release
 New Compiler Flags
 --
 
-.. _target_os_detail:
-
-Target OS macros extension
-^^
-A pair of new flags ``-fdefine-target-os-macros`` and
-``-fno-define-target-os-macros`` has been added to Clang to enable/disable the
-extension to provide built-in definitions of a list of ``TARGET_OS_*`` macros
-based on the target triple.
-
-The extension is enabled by default for Darwin (Apple platform) targets.
-
 Deprecated Compiler Flags
 -
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Docs] Add release note about Clang-defined target OS macros … (PR #80045)

2024-02-21 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w closed https://github.com/llvm/llvm-project/pull/80045
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Fix] Disable fdefine-target-os-macros for now" (PR #78353)

2024-01-16 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w created 
https://github.com/llvm/llvm-project/pull/78353

https://github.com/llvm/llvm-test-suite/pull/65 fixed the llvm-test-suite 
errors. Reapply the change to enable `fdefine-target-os-macros` by default for 
Darwin targets.

This reverts commit 63be986f612c175559efffed9daebcb944fa5cea.

>From 925a7eb15d04bb64adff3663244aad4b7b05f3d6 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 14 Dec 2023 15:44:06 -0800
Subject: [PATCH] Revert "[Fix] Disable fdefine-target-os-macros for now"

Reapply the change to enable `fdefine-target-os-macros` by default for
Darwin targets.

This reverts commit 63be986f612c175559efffed9daebcb944fa5cea.
---
 clang/lib/Driver/ToolChains/Darwin.cpp   |  4 +++
 clang/test/Driver/fdefine-target-os-macros.c | 29 +++-
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 65846cace461e3..8f24e5287e198c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2917,6 +2917,10 @@ void Darwin::addClangTargetOptions(const 
llvm::opt::ArgList ,
   // to fix the same problem with C++ headers, and is generally fragile.
   if (!sdkSupportsBuiltinModules(TargetPlatform, SDKInfo))
 CC1Args.push_back("-fbuiltin-headers-in-system-modules");
+
+  if (!DriverArgs.hasArgNoClaim(options::OPT_fdefine_target_os_macros,
+options::OPT_fno_define_target_os_macros))
+CC1Args.push_back("-fdefine-target-os-macros");
 }
 
 void Darwin::addClangCC1ASTargetOptions(
diff --git a/clang/test/Driver/fdefine-target-os-macros.c 
b/clang/test/Driver/fdefine-target-os-macros.c
index 030d4ce34cb282..d7379dd3d5396b 100644
--- a/clang/test/Driver/fdefine-target-os-macros.c
+++ b/clang/test/Driver/fdefine-target-os-macros.c
@@ -1,12 +1,11 @@
 // RUN: %clang -### --target=arm64-apple-darwin %s 2>&1 | FileCheck %s 
--check-prefix=DARWIN-DEFAULT
-// DARWIN-DEFAULT-NOT: "-fdefine-target-os-macros"
+// DARWIN-DEFAULT: "-fdefine-target-os-macros"
 
 // RUN: %clang -### --target=arm-none-linux-gnu %s 2>&1 | FileCheck %s 
--check-prefix=NON-DARWIN-DEFAULT
 // RUN: %clang -### --target=x86_64-pc-win32 %s 2>&1 | FileCheck %s 
--check-prefix=NON-DARWIN-DEFAULT
 // NON-DARWIN-DEFAULT-NOT: "-fdefine-target-os-macros"
 
-// RUN: %clang -dM -E --target=arm64-apple-macos \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-macos %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=1 \
 // RUN:-DIPHONE=0  \
@@ -21,8 +20,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -37,8 +35,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios-macabi \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios-macabi %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -53,8 +50,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios-simulator \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios-simulator %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -69,8 +65,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-tvos \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-tvos %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -85,8 +80,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-tvos-simulator \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-tvos-simulator %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -101,8 +95,7 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-watchos \
-// RUN:-fdefine-target-os-macros %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-watchos %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1

[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-17 Thread Zixu Wang via cfe-commits

zixu-w wrote:

> > It looks like this breaks building at least `MultiSource` from 
> > https://github.com/llvm/llvm-test-suite/. The first failure I see is when 
> > building `llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c`
> > ```
> > In file included from 
> > /llvm-test-suite/MultiSource/Applications/ClamAV/zlib_zutil.c:10:
> > In file included from 
> > test-suites/llvm-test-suite/MultiSource/Applications/ClamAV/zlib/gzguts.h:21:
> > ../usr/include/stdio.h:220:7: error: expected identifier or '('
> >   220 | FILE*fdopen(int, const char *) 
> > __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
> >   |  ^
> > llvm-test-suite/MultiSource/Applications/ClamAV/zlib/zutil.h:140:33: note: 
> > expanded from macro 'fdopen'
> >   140 | #define fdopen(fd,mode) NULL /* No fdopen() */
> >   | ^
> > llvm-project/builds/release-with-assertions/ccache-stage1/lib/clang/18/include/__stddef_null.h:26:16:
> >  note: expanded from macro 'NULL'
> >26 | #define NULL ((void*)0)
> >   |^
> > ```
> 
> These are actually part of zlib, so apart from llvm test suite having been 
> broken by this (but was fixed), plain zlib has been broken too (although 
> arguably, zlib is where the real issue is).

We have provided a fix for zlib (https://github.com/madler/zlib/pull/895) which 
was accepted by @madler.

https://github.com/llvm/llvm-project/pull/74676
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-17 Thread Zixu Wang via cfe-commits

zixu-w wrote:

> > We have provided a fix for zlib 
> > ([madler/zlib#895](https://github.com/madler/zlib/pull/895)) which was 
> > accepted by @madler.
> 
> But nowhere released, not even in the repository :(

Yeah... Not entirely familiar with the zlib development and contribution 
process, but looks like most of the PRs were just closed and changes committed 
separately some time after (presumably with a release?).

https://github.com/llvm/llvm-project/pull/74676
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Ensure typedef to pointer types are preserved (PR #78584)

2024-01-18 Thread Zixu Wang via cfe-commits

zixu-w wrote:

IIUC this is fixed by just moving the processing of elaborated types before 
pointers right? Curious what do the original declaration fragments look like.

https://github.com/llvm/llvm-project/pull/78584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Ensure typedef to pointer types are preserved (PR #78584)

2024-01-18 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/78584
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-07 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w updated 
https://github.com/llvm/llvm-project/pull/74676

>From f02d0c7323fa8fb357bd0228f6746b7f878eaa59 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 14 Sep 2023 17:06:24 -0700
Subject: [PATCH] [clang][PP] Add extension to predefine target OS macros

Add an extension feature `define-target-os-macros` that enables clang
to provide definitions of common TARGET_OS_* conditional macros.
The extension is enabled in the Darwin toolchain driver.
---
 clang/include/clang/Basic/Features.def|   2 +
 clang/include/clang/Basic/TargetOSMacros.def  |  55 
 clang/include/clang/Driver/Options.td |   3 +
 clang/include/clang/Lex/PreprocessorOptions.h |   3 +
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Driver/ToolChains/Darwin.cpp|   4 +
 clang/lib/Frontend/CompilerInvocation.cpp |   7 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   9 +
 clang/test/Driver/fdefine-target-os-macros.c  | 241 ++
 9 files changed, 327 insertions(+)
 create mode 100644 clang/include/clang/Basic/TargetOSMacros.def
 create mode 100644 clang/test/Driver/fdefine-target-os-macros.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index adaf2e413f2f6d..df1eff8cbcc9f0 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -89,6 +89,8 @@ FEATURE(blocks, LangOpts.Blocks)
 FEATURE(c_thread_safety_attributes, true)
 FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
 FEATURE(cxx_rtti, LangOpts.RTTI &)
+EXTENSION(define_target_os_macros,
+  PP.getPreprocessorOpts().DefineTargetOSMacros)
 FEATURE(enumerator_attributes, true)
 FEATURE(nullability, true)
 FEATURE(nullability_on_arrays, true)
diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
new file mode 100644
index 00..dfc2e033f6fd0d
--- /dev/null
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -0,0 +1,55 @@
+//===--- TargetOSMacros.def - Target OS macros --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file specifies the predefined TARGET_OS_* conditional macros.
+// A target macro `Name` should be defined if `Predicate` evaluates to true.
+// The macro expects `const llvm::Triple ` and the class `llvm::Triple`
+// to be available for the predicate.
+//
+//===--===//
+
+#ifndef TARGET_OS
+#define TARGET_OS(Name, Predicate)
+#endif
+
+// Windows targets.
+TARGET_OS(TARGET_OS_WIN32, Triple.isOSWindows())
+TARGET_OS(TARGET_OS_WINDOWS, Triple.isOSWindows())
+
+// Linux target.
+TARGET_OS(TARGET_OS_LINUX, Triple.isOSLinux())
+
+// Unix target.
+TARGET_OS(TARGET_OS_UNIX, Triple.isOSNetBSD() ||
+  Triple.isOSFreeBSD() ||
+  Triple.isOSOpenBSD() ||
+  Triple.isOSSolaris())
+
+// Apple (Mac) targets.
+TARGET_OS(TARGET_OS_MAC, Triple.isOSDarwin())
+TARGET_OS(TARGET_OS_OSX, Triple.isMacOSX())
+TARGET_OS(TARGET_OS_IPHONE, Triple.isiOS() || Triple.isTvOS() ||
+Triple.isWatchOS())
+// Triple::isiOS() also includes tvOS
+TARGET_OS(TARGET_OS_IOS, Triple.getOS() == llvm::Triple::IOS)
+TARGET_OS(TARGET_OS_TV, Triple.isTvOS())
+TARGET_OS(TARGET_OS_WATCH, Triple.isWatchOS())
+TARGET_OS(TARGET_OS_DRIVERKIT, Triple.isDriverKit())
+TARGET_OS(TARGET_OS_MACCATALYST, Triple.isMacCatalystEnvironment())
+TARGET_OS(TARGET_OS_SIMULATOR, Triple.isSimulatorEnvironment())
+
+// Deprecated Apple target conditionals.
+TARGET_OS(TARGET_OS_EMBEDDED, (Triple.isiOS() || Triple.isTvOS() \
+   || Triple.isWatchOS()) \
+   && !Triple.isMacCatalystEnvironment() \
+   && !Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
+TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
+
+#undef TARGET_OS
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0eec2b35263762..b959fd20fe413d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1818,6 +1818,9 @@ def fcomment_block_commands : CommaJoined<["-"], 
"fcomment-block-commands=">, Gr
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 
MarshallingInfoStringVector>;
+defm define_target_os_macros : OptInCC1FFlag<"define-target-os-macros",
+  "Enable", "Disable", " predefined target OS macros",

[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-07 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w closed https://github.com/llvm/llvm-project/pull/74676
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Fix] Disable fdefine-target-os-macros for now (PR #74886)

2023-12-08 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w created 
https://github.com/llvm/llvm-project/pull/74886

https://github.com/llvm/llvm-project/pull/74676 landed the work to implement 
`-fdefine-target-os-macros` and enabled the extension for the Darwin driver. 
However it is breaking some test builds. Leave the extension disabled for now 
until we can fix/workaround the build failures.

>From 63be986f612c175559efffed9daebcb944fa5cea Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Fri, 8 Dec 2023 12:58:15 -0800
Subject: [PATCH] [Fix] Disable fdefine-target-os-macros for now

https://github.com/llvm/llvm-project/pull/74676 landed the work to
implement `-fdefine-target-os-macros` and enabled the extension for
the Darwin driver. However it is breaking some test builds.
Leave the extension disabled for now until we can fix/workaround the
build failures.
---
 clang/lib/Driver/ToolChains/Darwin.cpp   |  4 ---
 clang/test/Driver/fdefine-target-os-macros.c | 29 +---
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index d3005d69e92bbf..f09bc27d7d2c0e 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2916,10 +2916,6 @@ void Darwin::addClangTargetOptions(const 
llvm::opt::ArgList ,
   // to fix the same problem with C++ headers, and is generally fragile.
   if (!sdkSupportsBuiltinModules(TargetPlatform, SDKInfo))
 CC1Args.push_back("-fbuiltin-headers-in-system-modules");
-
-  if (!DriverArgs.hasArgNoClaim(options::OPT_fdefine_target_os_macros,
-options::OPT_fno_define_target_os_macros))
-CC1Args.push_back("-fdefine-target-os-macros");
 }
 
 void Darwin::addClangCC1ASTargetOptions(
diff --git a/clang/test/Driver/fdefine-target-os-macros.c 
b/clang/test/Driver/fdefine-target-os-macros.c
index d7379dd3d5396b..030d4ce34cb282 100644
--- a/clang/test/Driver/fdefine-target-os-macros.c
+++ b/clang/test/Driver/fdefine-target-os-macros.c
@@ -1,11 +1,12 @@
 // RUN: %clang -### --target=arm64-apple-darwin %s 2>&1 | FileCheck %s 
--check-prefix=DARWIN-DEFAULT
-// DARWIN-DEFAULT: "-fdefine-target-os-macros"
+// DARWIN-DEFAULT-NOT: "-fdefine-target-os-macros"
 
 // RUN: %clang -### --target=arm-none-linux-gnu %s 2>&1 | FileCheck %s 
--check-prefix=NON-DARWIN-DEFAULT
 // RUN: %clang -### --target=x86_64-pc-win32 %s 2>&1 | FileCheck %s 
--check-prefix=NON-DARWIN-DEFAULT
 // NON-DARWIN-DEFAULT-NOT: "-fdefine-target-os-macros"
 
-// RUN: %clang -dM -E --target=arm64-apple-macos %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-macos \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=1 \
 // RUN:-DIPHONE=0  \
@@ -20,7 +21,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -35,7 +37,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios-macabi %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios-macabi \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -50,7 +53,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-ios-simulator %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-ios-simulator \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -65,7 +69,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-tvos %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-tvos \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -80,7 +85,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-tvos-simulator %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-tvos-simulator \
+// RUN:-fdefine-target-os-macros %s 2>&1 \
 // RUN: | FileCheck %s -DMAC=1 \
 // RUN:-DOSX=0 \
 // RUN:-DIPHONE=1  \
@@ -95,7 +101,8 @@
 // RUN:-DLINUX=0   \
 // RUN:-DUNIX=0
 
-// RUN: %clang -dM -E --target=arm64-apple-watchos %s 2>&1 \
+// RUN: %clang -dM -E --target=arm64-apple-watchos \
+// 

[clang] [Fix] Disable fdefine-target-os-macros for now (PR #74886)

2023-12-08 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w closed https://github.com/llvm/llvm-project/pull/74886
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-06 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w updated 
https://github.com/llvm/llvm-project/pull/74676

>From cdc7cf721a7d4a6bf318181ea3f37adf7c571ed1 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 14 Sep 2023 17:06:24 -0700
Subject: [PATCH] [clang][PP] Add extension to predefine target OS macros

Add an extension feature `define-target-os-macros` that enables clang
to provide definitions of common TARGET_OS_* conditional macros.
The extension is enabled in the Darwin toolchain driver.
---
 clang/include/clang/Basic/Features.def|   2 +
 clang/include/clang/Basic/TargetOSMacros.def  |  55 
 clang/include/clang/Driver/Options.td |   3 +
 clang/include/clang/Lex/PreprocessorOptions.h |   3 +
 clang/lib/Driver/ToolChains/Darwin.cpp|   4 +
 clang/lib/Frontend/CompilerInvocation.cpp |   7 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   9 ++
 .../Driver/darwin-fdefine-target-os-macros.c  | 131 ++
 8 files changed, 214 insertions(+)
 create mode 100644 clang/include/clang/Basic/TargetOSMacros.def
 create mode 100644 clang/test/Driver/darwin-fdefine-target-os-macros.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index adaf2e413f2f6d..df1eff8cbcc9f0 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -89,6 +89,8 @@ FEATURE(blocks, LangOpts.Blocks)
 FEATURE(c_thread_safety_attributes, true)
 FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
 FEATURE(cxx_rtti, LangOpts.RTTI &)
+EXTENSION(define_target_os_macros,
+  PP.getPreprocessorOpts().DefineTargetOSMacros)
 FEATURE(enumerator_attributes, true)
 FEATURE(nullability, true)
 FEATURE(nullability_on_arrays, true)
diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
new file mode 100644
index 00..dfc2e033f6fd0d
--- /dev/null
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -0,0 +1,55 @@
+//===--- TargetOSMacros.def - Target OS macros --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file specifies the predefined TARGET_OS_* conditional macros.
+// A target macro `Name` should be defined if `Predicate` evaluates to true.
+// The macro expects `const llvm::Triple ` and the class `llvm::Triple`
+// to be available for the predicate.
+//
+//===--===//
+
+#ifndef TARGET_OS
+#define TARGET_OS(Name, Predicate)
+#endif
+
+// Windows targets.
+TARGET_OS(TARGET_OS_WIN32, Triple.isOSWindows())
+TARGET_OS(TARGET_OS_WINDOWS, Triple.isOSWindows())
+
+// Linux target.
+TARGET_OS(TARGET_OS_LINUX, Triple.isOSLinux())
+
+// Unix target.
+TARGET_OS(TARGET_OS_UNIX, Triple.isOSNetBSD() ||
+  Triple.isOSFreeBSD() ||
+  Triple.isOSOpenBSD() ||
+  Triple.isOSSolaris())
+
+// Apple (Mac) targets.
+TARGET_OS(TARGET_OS_MAC, Triple.isOSDarwin())
+TARGET_OS(TARGET_OS_OSX, Triple.isMacOSX())
+TARGET_OS(TARGET_OS_IPHONE, Triple.isiOS() || Triple.isTvOS() ||
+Triple.isWatchOS())
+// Triple::isiOS() also includes tvOS
+TARGET_OS(TARGET_OS_IOS, Triple.getOS() == llvm::Triple::IOS)
+TARGET_OS(TARGET_OS_TV, Triple.isTvOS())
+TARGET_OS(TARGET_OS_WATCH, Triple.isWatchOS())
+TARGET_OS(TARGET_OS_DRIVERKIT, Triple.isDriverKit())
+TARGET_OS(TARGET_OS_MACCATALYST, Triple.isMacCatalystEnvironment())
+TARGET_OS(TARGET_OS_SIMULATOR, Triple.isSimulatorEnvironment())
+
+// Deprecated Apple target conditionals.
+TARGET_OS(TARGET_OS_EMBEDDED, (Triple.isiOS() || Triple.isTvOS() \
+   || Triple.isWatchOS()) \
+   && !Triple.isMacCatalystEnvironment() \
+   && !Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
+TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
+
+#undef TARGET_OS
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0eec2b35263762..b959fd20fe413d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1818,6 +1818,9 @@ def fcomment_block_commands : CommaJoined<["-"], 
"fcomment-block-commands=">, Gr
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 
MarshallingInfoStringVector>;
+defm define_target_os_macros : OptInCC1FFlag<"define-target-os-macros",
+  "Enable", "Disable", " predefined target OS macros",
+  [ClangOption, CC1Option]>;
 def 

[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2023-12-06 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w created 
https://github.com/llvm/llvm-project/pull/74676

Add an extension feature `define-target-os-macros` that enables clang to 
provide definitions of common TARGET_OS_* conditional macros. The extension is 
enabled in the Darwin toolchain driver.

>From 2812f69940451b810b8aa9a580e98a4a22a89967 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 14 Sep 2023 17:06:24 -0700
Subject: [PATCH] [clang][PP] Add extension to predefine target OS macros

Add an extension feature `define-target-os-macros` that enables clang
to provide definitions of common TARGET_OS_* conditional macros.
The extension is enabled in the Darwin toolchain driver.
---
 clang/include/clang/Basic/Features.def|   2 +
 clang/include/clang/Basic/TargetOSMacros.def  |  55 
 clang/include/clang/Driver/Options.td |   3 +
 clang/include/clang/Lex/PreprocessorOptions.h |   3 +
 clang/lib/Driver/ToolChains/Darwin.cpp|   4 +
 clang/lib/Frontend/CompilerInvocation.cpp |   7 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   9 ++
 .../Driver/darwin-fdefine-target-os-macros.c  | 131 ++
 8 files changed, 214 insertions(+)
 create mode 100644 clang/include/clang/Basic/TargetOSMacros.def
 create mode 100644 clang/test/Driver/darwin-fdefine-target-os-macros.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index adaf2e413f2f6..df1eff8cbcc9f 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -89,6 +89,8 @@ FEATURE(blocks, LangOpts.Blocks)
 FEATURE(c_thread_safety_attributes, true)
 FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
 FEATURE(cxx_rtti, LangOpts.RTTI &)
+EXTENSION(define_target_os_macros,
+  PP.getPreprocessorOpts().DefineTargetOSMacros)
 FEATURE(enumerator_attributes, true)
 FEATURE(nullability, true)
 FEATURE(nullability_on_arrays, true)
diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
new file mode 100644
index 0..dfc2e033f6fd0
--- /dev/null
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -0,0 +1,55 @@
+//===--- TargetOSMacros.def - Target OS macros --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file specifies the predefined TARGET_OS_* conditional macros.
+// A target macro `Name` should be defined if `Predicate` evaluates to true.
+// The macro expects `const llvm::Triple ` and the class `llvm::Triple`
+// to be available for the predicate.
+//
+//===--===//
+
+#ifndef TARGET_OS
+#define TARGET_OS(Name, Predicate)
+#endif
+
+// Windows targets.
+TARGET_OS(TARGET_OS_WIN32, Triple.isOSWindows())
+TARGET_OS(TARGET_OS_WINDOWS, Triple.isOSWindows())
+
+// Linux target.
+TARGET_OS(TARGET_OS_LINUX, Triple.isOSLinux())
+
+// Unix target.
+TARGET_OS(TARGET_OS_UNIX, Triple.isOSNetBSD() ||
+  Triple.isOSFreeBSD() ||
+  Triple.isOSOpenBSD() ||
+  Triple.isOSSolaris())
+
+// Apple (Mac) targets.
+TARGET_OS(TARGET_OS_MAC, Triple.isOSDarwin())
+TARGET_OS(TARGET_OS_OSX, Triple.isMacOSX())
+TARGET_OS(TARGET_OS_IPHONE, Triple.isiOS() || Triple.isTvOS() ||
+Triple.isWatchOS())
+// Triple::isiOS() also includes tvOS
+TARGET_OS(TARGET_OS_IOS, Triple.getOS() == llvm::Triple::IOS)
+TARGET_OS(TARGET_OS_TV, Triple.isTvOS())
+TARGET_OS(TARGET_OS_WATCH, Triple.isWatchOS())
+TARGET_OS(TARGET_OS_DRIVERKIT, Triple.isDriverKit())
+TARGET_OS(TARGET_OS_MACCATALYST, Triple.isMacCatalystEnvironment())
+TARGET_OS(TARGET_OS_SIMULATOR, Triple.isSimulatorEnvironment())
+
+// Deprecated Apple target conditionals.
+TARGET_OS(TARGET_OS_EMBEDDED, (Triple.isiOS() || Triple.isTvOS() \
+   || Triple.isWatchOS()) \
+   && !Triple.isMacCatalystEnvironment() \
+   && !Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
+TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
+TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
+
+#undef TARGET_OS
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0eec2b3526376..b959fd20fe413 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1818,6 +1818,9 @@ def fcomment_block_commands : CommaJoined<["-"], 
"fcomment-block-commands=">, Gr
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 

[clang] [clang][PP] Add extension to predefine target OS macros (PR #74676)

2024-01-25 Thread Zixu Wang via cfe-commits

zixu-w wrote:

> Is the motivation for this change in behavior (on macOS) documented 
> somewhere? Besides zlib as already discussed above, pre-defining 
> `TARGET_OS_MAC` apparently at least also affects some libpng builds (and I 
> ultimately had to globally set `-fno-define-target-os-macros` for now to make 
> a test build of LibreOffice and all its included external libraries work).

I should be able to put up documentation/release note regarding the change.

IMO, we've also noticed the issue and upstreamed a fix for libpng 
(https://github.com/pnggroup/libpng/pull/529)

https://github.com/llvm/llvm-project/pull/74676
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Fix] Disable fdefine-target-os-macros for now" (PR #78353)

2024-01-25 Thread Zixu Wang via cfe-commits

zixu-w wrote:


Hi @zmodem !
> Could you add a release note about this, explaining how it changes the macros 
> and what actions users should take?

That's a good idea, I should be able to put something up.
> 
> We've already seen that it broke zlib builds, and we're having issues with 
> libpng too in Chromium (https://crbug.com/1519899), so users are likely to 
> run into this.

FWIW, we've also noticed the issue and upstreamed a fix for libpng 
(https://github.com/pnggroup/libpng/pull/529)

https://github.com/llvm/llvm-project/pull/78353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs] Add release note about Clang-defined target OS macros (PR #79879)

2024-01-29 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w created 
https://github.com/llvm/llvm-project/pull/79879

None

>From b773a6911ef1f842b7d5d548c98109012d80dd10 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Thu, 25 Jan 2024 16:35:37 -0800
Subject: [PATCH] [Docs] Add release note about Clang-defined target OS macros

---
 clang/docs/ReleaseNotes.rst | 29 +
 1 file changed, 29 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05c42f8485d4ee3..29377f9537e88f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -49,6 +49,24 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
+Clang Frontend Potentially Breaking Changes
+---
+
+Target OS macros extension
+^^
+A new Clang extension (see :ref:`here `) is enabled for
+Darwin (Apple platform) targets. Clang now defines ``TARGET_OS_*`` macros for
+these targets, which could break existing code bases with improper checks for
+the ``TARGET_OS_`` macros. For example, existing checks might fail to include
+the ``TargetConditionals.h`` header from Apple SDKs and therefore leaving the
+macros undefined and guarded code unexercised.
+
+Affected code should be checked to see if it's still intended for the specific
+target and fixed accordingly.
+
+The extension can be turned off by the option ``-fno-define-target-os-macros``
+as a workaround.
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -83,6 +101,17 @@ Non-comprehensive list of changes in this release
 New Compiler Flags
 --
 
+.. _target_os_detail:
+
+Target OS macros extension
+^^
+A pair of new flags ``-fdefine-target-os-macros`` and
+``-fno-define-target-os-macros`` has been added to Clang to enable/disable the
+extension to provide built-in definitions of a list of ``TARGET_OS_*`` macros
+based on the target triple.
+
+The extension is enabled by default for Darwin (Apple platform) targets.
+
 Deprecated Compiler Flags
 -
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Docs] Add release note about Clang-defined target OS macros … (PR #80045)

2024-01-30 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w created 
https://github.com/llvm/llvm-project/pull/80045

…(#79879)"

This reverts commit b40d5b1b08564d23d5e0769892ebbc32447b2987.

The target OS macros work is included in the 18.x release. Move the release 
note to the release branch (https://github.com/llvm/llvm-project/pull/80044).

>From ddc37117a2c45415f271357e42edcc1f26cb0e31 Mon Sep 17 00:00:00 2001
From: Zixu Wang 
Date: Tue, 30 Jan 2024 10:44:21 -0800
Subject: [PATCH] Revert "[Docs] Add release note about Clang-defined target OS
 macros (#79879)"

This reverts commit b40d5b1b08564d23d5e0769892ebbc32447b2987.

The target OS macros work is included in the 18.x release. Move the
release note to the release branch.
---
 clang/docs/ReleaseNotes.rst | 29 -
 1 file changed, 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 323157c4db1f1..89302dfc09734 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -49,24 +49,6 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 
 
-Clang Frontend Potentially Breaking Changes

-
-Target OS macros extension
-^^
-A new Clang extension (see :ref:`here `) is enabled for
-Darwin (Apple platform) targets. Clang now defines ``TARGET_OS_*`` macros for
-these targets, which could break existing code bases with improper checks for
-the ``TARGET_OS_`` macros. For example, existing checks might fail to include
-the ``TargetConditionals.h`` header from Apple SDKs and therefore leaving the
-macros undefined and guarded code unexercised.
-
-Affected code should be checked to see if it's still intended for the specific
-target and fixed accordingly.
-
-The extension can be turned off by the option ``-fno-define-target-os-macros``
-as a workaround.
-
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -115,17 +97,6 @@ Non-comprehensive list of changes in this release
 New Compiler Flags
 --
 
-.. _target_os_detail:
-
-Target OS macros extension
-^^
-A pair of new flags ``-fdefine-target-os-macros`` and
-``-fno-define-target-os-macros`` has been added to Clang to enable/disable the
-extension to provide built-in definitions of a list of ``TARGET_OS_*`` macros
-based on the target triple.
-
-The extension is enabled by default for Darwin (Apple platform) targets.
-
 Deprecated Compiler Flags
 -
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Fix] Disable fdefine-target-os-macros for now" (PR #78353)

2024-01-16 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w closed https://github.com/llvm/llvm-project/pull/78353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)

2024-04-17 Thread Zixu Wang via cfe-commits


@@ -259,7 +259,10 @@ bool Options::processLinkerOptions(InputArgList ) {
   if (auto *Arg = Args.getLastArg(drv::OPT_umbrella))
 LinkerOpts.ParentUmbrella = Arg->getValue();
 
-  LinkerOpts.IsDylib = Args.hasArg(drv::OPT_dynamiclib);

zixu-w wrote:

Is this expected to get removed?

https://github.com/llvm/llvm-project/pull/88750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)

2024-04-17 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.


https://github.com/llvm/llvm-project/pull/88750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Support mutually exclusive parse options (PR #90686)

2024-05-08 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.


https://github.com/llvm/llvm-project/pull/90686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Zixu Wang via cfe-commits


@@ -19,7 +19,7 @@ namespace clang::installapi {
 GlobalRecord *FrontendRecordsSlice::addGlobal(
 StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV,
 const clang::AvailabilityInfo Avail, const Decl *D, const HeaderType 
Access,
-SymbolFlags Flags) {
+SymbolFlags Flags, bool Inlined) {

zixu-w wrote:

How is this parameter used in this function?

https://github.com/llvm/llvm-project/pull/83952
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.


https://github.com/llvm/llvm-project/pull/83952
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Capture & compare load commands that may differ per arch slice (PR #87674)

2024-04-05 Thread Zixu Wang via cfe-commits


@@ -0,0 +1,111 @@
+//===- DiagnosticBuilderWrappers.cpp *- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DiagnosticBuilderWrappers.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TextAPI/Platform.h"
+
+using clang::DiagnosticBuilder;
+
+namespace llvm {
+namespace MachO {
+const DiagnosticBuilder <<(const DiagnosticBuilder ,
+const Architecture ) {
+  DB.AddString(getArchitectureName(Arch));
+  return DB;
+}
+
+const DiagnosticBuilder <<(const DiagnosticBuilder ,
+const ArchitectureSet ) {
+  DB.AddString(std::string(ArchSet));
+  return DB;
+}
+
+const DiagnosticBuilder <<(const DiagnosticBuilder ,
+const PlatformType ) {
+  DB.AddString(getPlatformName(Platform));
+  return DB;
+}
+
+const DiagnosticBuilder <<(const DiagnosticBuilder ,
+const PlatformVersionSet ) {
+  std::string PlatformAsString;
+  raw_string_ostream Stream(PlatformAsString);
+
+  Stream << "[ ";
+  bool NeedsComma = false;
+  for (auto &[Platform, Version] : Platforms) {
+if (NeedsComma)

zixu-w wrote:

`STLExtras` has an `interleaveComma(const Container , StreamT , 
UnaryFunctor each_fn)` that could simplify some of the trouble here.

https://github.com/llvm/llvm-project/pull/87674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Capture & compare load commands that may differ per arch slice (PR #87674)

2024-04-05 Thread Zixu Wang via cfe-commits


@@ -702,5 +724,179 @@ DylibVerifier::Result 
DylibVerifier::verifyRemainingSymbols() {
   return getState();
 }
 
+bool DylibVerifier::verifyBinaryAttrs(const ArrayRef ProvidedTargets,
+  const BinaryAttrs ,
+  const LibAttrs ,
+  const LibAttrs ,
+  const LibAttrs ,
+  const FileType ) {
+  assert(!Dylib.empty() && "Need dylib to verify.");
+
+  // Pickup any load commands that can differ per slice to compare.
+  TargetList DylibTargets;
+  LibAttrs DylibReexports;
+  LibAttrs DylibClients;
+  LibAttrs DylibRPaths;
+  for (const std::shared_ptr  : Dylib) {
+DylibTargets.push_back(RS->getTarget());
+const BinaryAttrs  = RS->getBinaryAttrs();
+for (const StringRef LibName : BinInfo.RexportedLibraries)
+  DylibReexports[LibName].set(DylibTargets.back().Arch);
+for (const StringRef LibName : BinInfo.AllowableClients)
+  DylibClients[LibName].set(DylibTargets.back().Arch);
+// Compare attributes that are only representable in >= TBD_V5.
+if (FT >= FileType::TBD_V5)
+  for (const StringRef Name : BinInfo.RPaths)
+DylibRPaths[Name].set(DylibTargets.back().Arch);
+  }
+
+  // Check targets first.
+  ArchitectureSet ProvidedArchs = mapToArchitectureSet(ProvidedTargets);
+  ArchitectureSet DylibArchs = mapToArchitectureSet(DylibTargets);
+  if (ProvidedArchs != DylibArchs) {
+Ctx.Diag->Report(diag::err_architecture_mismatch)
+<< ProvidedArchs << DylibArchs;
+return false;
+  }
+  auto ProvidedPlatforms = mapToPlatformVersionSet(ProvidedTargets);
+  auto DylibPlatforms = mapToPlatformVersionSet(DylibTargets);
+  if (ProvidedPlatforms != DylibPlatforms) {
+const bool DiffMinOS =
+mapToPlatformSet(ProvidedTargets) == mapToPlatformSet(DylibTargets);
+if (DiffMinOS)
+  Ctx.Diag->Report(diag::warn_platform_mismatch)
+  << ProvidedPlatforms << DylibPlatforms;
+else {
+  Ctx.Diag->Report(diag::err_platform_mismatch)
+  << ProvidedPlatforms << DylibPlatforms;
+  return false;
+}
+  }
+
+  // Because InstallAPI requires certain attributes to match across 
architecture
+  // slices, take the first one to compare those with.
+  const BinaryAttrs  = (*Dylib.begin())->getBinaryAttrs();
+
+  if (ProvidedBA.InstallName != DylibBA.InstallName) {
+Ctx.Diag->Report(diag::err_install_name_mismatch)
+<< ProvidedBA.InstallName << DylibBA.InstallName;
+return false;
+  }
+
+  if (ProvidedBA.CurrentVersion != DylibBA.CurrentVersion) {
+Ctx.Diag->Report(diag::err_current_version_mismatch)
+<< ProvidedBA.CurrentVersion << DylibBA.CurrentVersion;
+return false;
+  }
+
+  if (ProvidedBA.CompatVersion != DylibBA.CompatVersion) {
+Ctx.Diag->Report(diag::err_compatibility_version_mismatch)
+<< ProvidedBA.CompatVersion << DylibBA.CompatVersion;
+return false;
+  }
+
+  if (ProvidedBA.AppExtensionSafe != DylibBA.AppExtensionSafe) {
+Ctx.Diag->Report(diag::err_appextension_safe_mismatch)
+<< (ProvidedBA.AppExtensionSafe ? "true" : "false")
+<< (DylibBA.AppExtensionSafe ? "true" : "false");
+return false;
+  }
+
+  if (!DylibBA.TwoLevelNamespace) {
+Ctx.Diag->Report(diag::err_no_twolevel_namespace);
+return false;
+  }
+
+  if (ProvidedBA.OSLibNotForSharedCache != DylibBA.OSLibNotForSharedCache) {
+Ctx.Diag->Report(diag::err_shared_cache_eligiblity_mismatch)
+<< (ProvidedBA.OSLibNotForSharedCache ? "true" : "false")
+<< (DylibBA.OSLibNotForSharedCache ? "true" : "false");
+return false;
+  }
+
+  if (ProvidedBA.ParentUmbrella.empty() && !DylibBA.ParentUmbrella.empty()) {
+Ctx.Diag->Report(diag::err_parent_umbrella_missing)
+<< "installAPI option" << DylibBA.ParentUmbrella;
+return false;
+  }
+
+  if (!ProvidedBA.ParentUmbrella.empty() && !DylibBA.ParentUmbrella.empty()) {

zixu-w wrote:

Should this be
```
!ProvidedBA.ParentUmbrella.empty() &&  DylibBA.ParentUmbrella.empty()
  ^ no negation here
```
?

https://github.com/llvm/llvm-project/pull/87674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Capture & compare load commands that may differ per arch slice (PR #87674)

2024-04-05 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.


https://github.com/llvm/llvm-project/pull/87674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Extend define-target-os-macros to support XROS. (PR #82833)

2024-02-27 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.

LGTM. Thanks for making the change!

https://github.com/llvm/llvm-project/pull/82833
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Pick up input headers by directory traversal (PR #94508)

2024-06-06 Thread Zixu Wang via cfe-commits


@@ -97,6 +97,14 @@ class HeaderFile {
   Other.Excluded, Other.Extra,
   Other.Umbrella);
   }
+
+  bool operator<(const HeaderFile ) const {

zixu-w wrote:

What's the reasoning for the ordering? Might be easier to understand in the 
future with some comments.

https://github.com/llvm/llvm-project/pull/94508
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits