[llvm] [compiler-rt] [libc] [libcxx] [flang] [clang] [lld] [lldb] [clang-tools-extra] [lld-macho] Find objects in library search path (PR #78628)

2024-01-22 Thread Vy Nguyen via cfe-commits


@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: mkdir -p %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s 
-o %t/hello.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
+# RUN: %lld -L %t %t/main.o %t/hello.o -o %t/a.out

oontvoo wrote:

would you mind putting it in another PR? we can get it merged there. Thanks!

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


[clang] e60b30d - Reland "D144999 [MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs."

2023-06-07 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2023-06-07T10:03:50-04:00
New Revision: e60b30d5e3878e7d91f8872ec4c4dca00d4a2dfc

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

LOG: Reland "D144999 [MC][MachO]Only emits compact-unwind format for 
"canonical" personality symbols. For the rest, use DWARFs."

Reasons for rolling forward:
- the crash reported from Chromium was fixed in D151824 (not related to 
this patch at all)
- since D152824 was committed, it should now be safe to roll this forward.

New change:
- add an additional _ in name check

This reverts commit 4980eead4d0b4666d53dad07afb091375b3a13a0.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/femit-dwarf-unwind.c
clang/test/Driver/femit-dwarf-unwind.s
clang/tools/driver/cc1as_main.cpp
lld/MachO/UnwindInfoSection.cpp
lld/test/MachO/Inputs/eh-frame-x86_64-r.o
lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
lld/test/MachO/compact-unwind-generated.test
lld/test/MachO/compact-unwind-lsda-folding.s
lld/test/MachO/compact-unwind-stack-ind.s
lld/test/MachO/compact-unwind.s
lld/test/MachO/eh-frame-personality-dedup.s
lld/test/MachO/eh-frame.s
lld/test/MachO/icf-only-lsda-folded.s
lld/test/MachO/icf.s
lld/test/MachO/invalid/compact-unwind-bad-reloc.s
lld/test/MachO/invalid/compact-unwind-personalities.s
llvm/include/llvm/MC/MCAsmBackend.h
llvm/include/llvm/MC/MCContext.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/test/CodeGen/X86/2014-08-29-CompactUnwind.ll
llvm/test/CodeGen/X86/compact-unwind.ll
llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
llvm/test/MC/X86/compact-unwind.s

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 5752c6e285b98..53d92c4c76673 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -114,6 +114,9 @@ CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when 
-fstack-size-section is enabl
 CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
   ///< enabled.
 
+///< Set when -femit-compact-unwind-non-canonical is enabled.
+CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0)
+
 ///< Set when -femit-dwarf-unwind is passed.
 ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
 llvm::EmitDwarfUnwindType::Default)

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3326db0791aaf..7fad5b27fdb6e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3285,6 +3285,9 @@ def femit_dwarf_unwind_EQ : Joined<["-"], 
"femit-dwarf-unwind=">,
   NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
   NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
   MarshallingInfoEnum, "Default">;
+defm emit_compact_unwind_non_canonical : 
BoolFOption<"emit-compact-unwind-non-canonical",
+  CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse,
+  PosFlag, 
NegFlag>;
 def g_Flag : Flag<["-"], "g">, Group,
 Flags<[CoreOption,FlangOption]>, HelpText<"Generate source-level debug 
information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d4498ebaf8dea..c736f38e01f65 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -454,6 +454,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
 
   Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
   Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
+  Options.MCOptions.EmitCompactUnwindNonCanonical =
+  CodeGenOpts.EmitCompactUnwindNonCanonical;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory =

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
inde

[clang] 09aaf53 - [RFC][MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs.

2023-05-18 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2023-05-18T13:27:47-04:00
New Revision: 09aaf53a05e3786eea374f3ce57574225036412d

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

LOG: [RFC][MC][MachO]Only emits compact-unwind format for "canonical" 
personality symbols. For the rest, use DWARFs.

Details: https://github.com/rust-lang/rust/issues/102754

The MachO format uses 2 bits to encode these personality funtions, with 0 
reserved for "no-personality".
This means we can only have up to 3 personality. There are already three 
popular personalities:  __gxx_personality_v0, __gcc_personality_v0, and 
__objc_personality_v0.
As a result, any system that needs custom-personality will run into a problem.

This patch implemented jyknight's proposal to simply force DWARFs for all 
non-canonical personality functions.

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/femit-dwarf-unwind.c
clang/test/Driver/femit-dwarf-unwind.s
clang/tools/driver/cc1as_main.cpp
lld/MachO/UnwindInfoSection.cpp
lld/test/MachO/Inputs/eh-frame-x86_64-r.o
lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
lld/test/MachO/compact-unwind-generated.test
lld/test/MachO/compact-unwind-lsda-folding.s
lld/test/MachO/compact-unwind-stack-ind.s
lld/test/MachO/compact-unwind.s
lld/test/MachO/eh-frame-personality-dedup.s
lld/test/MachO/eh-frame.s
lld/test/MachO/icf-only-lsda-folded.s
lld/test/MachO/icf.s
lld/test/MachO/invalid/compact-unwind-bad-reloc.s
lld/test/MachO/invalid/compact-unwind-personalities.s
llvm/include/llvm/MC/MCAsmBackend.h
llvm/include/llvm/MC/MCContext.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/test/CodeGen/X86/2014-08-29-CompactUnwind.ll
llvm/test/CodeGen/X86/compact-unwind.ll
llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
llvm/test/MC/X86/compact-unwind.s

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 5752c6e285b98..53d92c4c76673 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -114,6 +114,9 @@ CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when 
-fstack-size-section is enabl
 CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
   ///< enabled.
 
+///< Set when -femit-compact-unwind-non-canonical is enabled.
+CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0)
+
 ///< Set when -femit-dwarf-unwind is passed.
 ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
 llvm::EmitDwarfUnwindType::Default)

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f3026693e6d53..9f6922cbe5678 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3244,6 +3244,9 @@ def femit_dwarf_unwind_EQ : Joined<["-"], 
"femit-dwarf-unwind=">,
   NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
   NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
   MarshallingInfoEnum, "Default">;
+defm emit_compact_unwind_non_canonical : 
BoolFOption<"emit-compact-unwind-non-canonical",
+  CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse,
+  PosFlag, 
NegFlag>;
 def g_Flag : Flag<["-"], "g">, Group,
 Flags<[CoreOption,FlangOption]>, HelpText<"Generate source-level debug 
information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d62d00a156f1c..934e41c75f4d1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -454,6 +454,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
 
   Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
   Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
+  Options.MCOptions.EmitCompactUnwindNonCanonical =
+  CodeGenOpts.EmitCompactUnwindNonCanonical;
   Options.MCO

[clang] 0073fd8 - Add the thread sanitizer support for X86_64 WatchOS simulators

2022-12-09 Thread Vy Nguyen via cfe-commits

Author: Yifan Yang
Date: 2022-12-09T13:32:56-05:00
New Revision: 0073fd8d0dda533a5acb1c237a37ad270d24b711

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

LOG: Add the thread sanitizer support for X86_64 WatchOS simulators

Allow TSan in clang driver for X86_64 WatchOS simulator.

It was already functional, and Apple's downstream fork of clang allows it, but 
that change had not made it upstream yet.

Reviewed By: jyknight, yln

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index f77a51250c192..eba602529a086 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3277,11 +3277,10 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
   !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
 Res |= SanitizerKind::Vptr;
 
-  if ((IsX86_64 || IsAArch64) && isTargetMacOSBased()) {
+  if ((IsX86_64 || IsAArch64) &&
+  (isTargetMacOSBased() || isTargetIOSSimulator() ||
+   isTargetTvOSSimulator() || isTargetWatchOSSimulator())) {
 Res |= SanitizerKind::Thread;
-  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
-if (IsX86_64)
-  Res |= SanitizerKind::Thread;
   }
   return Res;
 }

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 6cf8bfa9be324..f5f5ceb220847 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -460,9 +460,21 @@
 // RUN: %clang --target=arm64-apple-macos -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-ARM64-MACOS
 // CHECK-TSAN-ARM64-MACOS-NOT: unsupported option
 
+// RUN: %clang --target=arm64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-IOSSIMULATOR
+// CHECK-TSAN-ARM64-IOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-WATCHOSSIMULATOR
+// CHECK-TSAN-ARM64-WATCHOSSIMULATOR-NOT: unsupported option
+
+// RUN: %clang --target=arm64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-ARM64-TVOSSIMULATOR
+// CHECK-TSAN-ARM64-TVOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-ios-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-IOSSIMULATOR
 // CHECK-TSAN-X86-64-IOSSIMULATOR-NOT: unsupported option
 
+// RUN: %clang --target=x86_64-apple-watchos-simulator -fsanitize=thread %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-WATCHOSSIMULATOR
+// CHECK-TSAN-X86-64-WATCHOSSIMULATOR-NOT: unsupported option
+
 // RUN: %clang --target=x86_64-apple-tvos-simulator -fsanitize=thread %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-X86-64-TVOSSIMULATOR
 // CHECK-TSAN-X86-64-TVOSSIMULATOR-NOT: unsupported option
 



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


[clang-tools-extra] 114c9fa - Add "status" to the list of absl libraries.

2020-08-13 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2020-08-13T16:08:14-04:00
New Revision: 114c9fa0e46f7bf1d05d92da70da116b19f16911

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

LOG: Add "status" to the list of absl libraries.

The Abseil-NoInternalDependenciesCheck currently mistakenly triggers on any 
usage of internal helpers even if it is within absl/status.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h 
b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
index 3f7529d1bbd0..f58ff5bc44b2 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -50,8 +50,8 @@ AST_POLYMORPHIC_MATCHER(
   static const char *AbseilLibraries[] = {
   "algorithm", "base", "container",   "debugging", "flags",
   "hash",  "iterator", "memory",  "meta",  "numeric",
-  "random","strings",  "synchronization", "time",  "types",
-  "utility"};
+  "random","strings",  "synchronization", "status","time",
+  "types", "utility"};
   return std::any_of(
   std::begin(AbseilLibraries), std::end(AbseilLibraries),
   [&](const char *Library) { return Path.startswith(Library); });



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


[clang] 17ea41e - Summary: [clang] Provide a way for WhileStmt to report the location of its LParen and RParen.

2020-07-10 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2020-07-10T21:31:16-04:00
New Revision: 17ea41e472566823e16d3a04661221fbd18d9fae

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

LOG: Summary: [clang] Provide a way for WhileStmt to report the location of its 
LParen and RParen.

Summary: This helps avoiding hacks downstream.

Reviewers: shafik

Subscribers: martong, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/Stmt.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Stmt.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 01d4301922f8..d3fad58fcf59 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -2277,6 +2277,8 @@ class WhileStmt final : public Stmt,
   enum { VarOffset = 0, BodyOffsetFromCond = 1 };
   enum { NumMandatoryStmtPtr = 2 };
 
+  SourceLocation LParenLoc, RParenLoc;
+
   unsigned varOffset() const { return VarOffset; }
   unsigned condOffset() const { return VarOffset + hasVarStorage(); }
   unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
@@ -2287,7 +2289,8 @@ class WhileStmt final : public Stmt,
 
   /// Build a while statement.
   WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
-SourceLocation WL);
+SourceLocation WL, SourceLocation LParenLoc,
+SourceLocation RParenLoc);
 
   /// Build an empty while statement.
   explicit WhileStmt(EmptyShell Empty, bool HasVar);
@@ -2295,7 +2298,8 @@ class WhileStmt final : public Stmt,
 public:
   /// Create a while statement.
   static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
-   Stmt *Body, SourceLocation WL);
+   Stmt *Body, SourceLocation WL,
+   SourceLocation LParenLoc, SourceLocation RParenLoc);
 
   /// Create an empty while statement optionally with storage for
   /// a condition variable.
@@ -2359,6 +2363,11 @@ class WhileStmt final : public Stmt,
   SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
   void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
 
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+
   SourceLocation getBeginLoc() const { return getWhileLoc(); }
   SourceLocation getEndLoc() const LLVM_READONLY {
 return getBody()->getEndLoc();

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 1d75515d494e..e809d87b59a0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2071,8 +2071,9 @@ class Parser : public CodeCompletionHandler {
   StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
   bool ParseParenExprOrCondition(StmtResult *InitStmt,
  Sema::ConditionResult &CondResult,
- SourceLocation Loc,
- Sema::ConditionKind CK);
+ SourceLocation Loc, Sema::ConditionKind CK,
+ SourceLocation *LParenLoc = nullptr,
+ SourceLocation *RParenLoc = nullptr);
   StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c3bebea0cccb..e75ac185eb2c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4377,7 +4377,8 @@ class Sema final {
 ConditionResult Cond);
   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
Stmt *Switch, Stmt *Body);
-  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond,
+  StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc,
+ConditionResult Cond, SourceLocation RParenLoc,
 Stmt *Body);
   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
  SourceLocation WhileLoc, SourceLocation CondLPar

[clang] a707da4 - Clang crashed while checking for deletion of copy and move ctors

2020-07-07 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2020-07-07T14:40:37-04:00
New Revision: a707da4728dea51c1446cf582a46fb271f3969c3

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

LOG: Clang crashed while checking for deletion of copy and move ctors

Crash:
   @ 0x559d129463fc  
clang::CXXRecordDecl::defaultedCopyConstructorIsDeleted()
@ 0x559d1288d3e5  
clang::Sema::checkIllFormedTrivialABIStruct()::$_7::operator()()
@ 0x559d12884c34  clang::Sema::checkIllFormedTrivialABIStruct()
@ 0x559d1288412e  clang::Sema::CheckCompletedCXXClass()
@ 0x559d1288d843  clang::Sema::ActOnFinishCXXMemberSpecification()
@ 0x559d12020109  clang::Parser::ParseCXXMemberSpecification()
@ 0x559d1201e80c  clang::Parser::ParseClassSpecifier()
@ 0x559d1204e807  clang::Parser::ParseDeclarationSpecifiers()
@ 0x559d120e9aa9  
clang::Parser::ParseSingleDeclarationAfterTemplate()
@ 0x559d120e8f21  
clang::Parser::ParseTemplateDeclarationOrSpecialization()
@ 0x559d120e8886  
clang::Parser::ParseDeclarationStartingWithTemplate()
@ 0x559d1204a1d4  clang::Parser::ParseDeclaration()
@ 0x559d12004b1d  clang::Parser::ParseExternalDeclaration()
@ 0x559d12017689  clang::Parser::ParseInnerNamespace()
@ 0x559d12017024  clang::Parser::ParseNamespace()
@ 0x559d1204a29b  clang::Parser::ParseDeclaration()
@ 0x559d12004c74  clang::Parser::ParseExternalDeclaration()

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/SemaCXX/attr-trivial-abi.cpp

Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaObjCXX/attr-trivial-abi.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ef555788ee0e..eb001a77518b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9719,6 +9719,10 @@ void Sema::checkIllFormedTrivialABIStruct(CXXRecordDecl 
&RD) {
 
   // Ill-formed if the copy and move constructors are deleted.
   auto HasNonDeletedCopyOrMoveConstructor = [&]() {
+// If the type is dependent, then assume it might have
+// implicit copy or move ctor because we won't know yet at this point.
+if (RD.isDependentType())
+  return true;
 if (RD.needsImplicitCopyConstructor() &&
 !RD.defaultedCopyConstructorIsDeleted())
   return true;

diff  --git a/clang/test/SemaCXX/attr-trivial-abi.cpp 
b/clang/test/SemaCXX/attr-trivial-abi.cpp
new file mode 100644
index ..334b471d2ab8
--- /dev/null
+++ b/clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' 
attribute only applies to classes}}
+
+// Should not crash.
+template 
+class __attribute__((trivial_abi)) a { a(a &&); };
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' 
cannot be applied to 'S3'}} expected-note {{is polymorphic}}
+  virtual void m();
+};
+
+struct S3_2 {
+  virtual void m();
+} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be 
applied to 'S3_2'}} expected-note {{is polymorphic}}
+
+struct __attribute__((trivial_abi)) S3_3 { // expected-warning {{'trivial_abi' 
cannot be applied to 'S3_3'}} expected-note {{has a field of a non-trivial 
class type}}
+  S3_3(S3_3 &&);
+  S3_2 s32;
+};
+
+// Diagnose invalid trivial_abi even when the type is templated because it has 
a non-trivial field.
+template 
+struct __attribute__((trivial_abi)) S3_4 { // expected-warning {{'trivial_abi' 
cannot be applied to 'S3_4'}} expected-note {{has a field of a non-trivial 
class type}}
+  S3_4(S3_4 &&);
+  S3_2 s32;
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // 
expected-warning {{'trivial_abi' cannot be applied to 'S5'}} expected-note 
{{has a virtual base}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' 
attribute takes no arguments}}
+  int a;
+};
+
+// Do not warn about deleted ctors  when 'trivial_abi' is used to annotate a 
template class.
+template 
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+template 
+struct S14 {
+  T a;
+};
+
+template 
+struct __attribute__((trivial_abi)) S15 : S14 {
+};
+
+S15 s15;
+
+template 
+struct __attribute__((trivial_abi)) S16 {
+  S14 a;
+};
+
+S16 s16;
+
+template 
+struct __attribute__((trivial_abi)) S17 {
+};

[clang] a21a462 - Make the diagnostic-missing-prototypes put the suggested `static` in front of `const` if exists.

2020-06-09 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2020-06-09T19:34:57-04:00
New Revision: a21a462051659d8e1281af7d11738b8abc0557dc

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

LOG: Make the diagnostic-missing-prototypes put the suggested `static` in front 
of `const` if exists.

Summary:
Consider: `const int* get_foo() {return nullptr;}`
The suggested fix should be `static const int* get_foo(){}`
and not `const static int* get_foo(){}`

Reviewers: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-missing-prototypes.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 401aea355c41..e6d4222d4b17 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14243,11 +14243,48 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 : FixItHint{});
 }
   } else {
+// Returns true if the token beginning at this Loc is `const`.
+auto isLocAtConst = [&](SourceLocation Loc, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  std::pair LocInfo = SM.getDecomposedLoc(Loc);
+  if (LocInfo.first.isInvalid())
+return false;
+
+  bool Invalid = false;
+  StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
+  if (Invalid)
+return false;
+
+  if (LocInfo.second > Buffer.size())
+return false;
+
+  const char *LexStart = Buffer.data() + LocInfo.second;
+  StringRef StartTok(LexStart, Buffer.size() - LocInfo.second);
+
+  return StartTok.consume_front("const") &&
+ (StartTok.empty() || isWhitespace(StartTok[0]) ||
+  StartTok.startswith("/*") || StartTok.startswith("//"));
+};
+
+auto findBeginLoc = [&]() {
+  // If the return type has `const` qualifier, we want to insert
+  // `static` before `const` (and not before the typename).
+  if ((FD->getReturnType()->isAnyPointerType() &&
+   FD->getReturnType()->getPointeeType().isConstQualified()) ||
+  FD->getReturnType().isConstQualified()) {
+// But only do this if we can determine where the `const` is.
+
+if (isLocAtConst(FD->getBeginLoc(), getSourceManager(),
+ getLangOpts()))
+
+  return FD->getBeginLoc();
+  }
+  return FD->getTypeSpecStartLoc();
+};
 Diag(FD->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
 << /* function */ 1
 << (FD->getStorageClass() == SC_None
-? FixItHint::CreateInsertion(FD->getTypeSpecStartLoc(),
- "static ")
+? FixItHint::CreateInsertion(findBeginLoc(), "static ")
 : FixItHint{});
   }
 

diff  --git a/clang/test/Sema/warn-missing-prototypes.c 
b/clang/test/Sema/warn-missing-prototypes.c
index 5940a49572ba..1830b3ff9e73 100644
--- a/clang/test/Sema/warn-missing-prototypes.c
+++ b/clang/test/Sema/warn-missing-prototypes.c
@@ -49,3 +49,60 @@ int main(void) { return 0; }
 void not_a_prototype_test(); // expected-note{{this declaration is not a 
prototype; add 'void' to make it a prototype for a zero-parameter function}}
 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:27-[[@LINE-1]]:27}:"void"
 void not_a_prototype_test() { } // expected-warning{{no previous prototype for 
function 'not_a_prototype_test'}}
+
+const int *get_const() { // expected-warning{{no previous prototype for 
function 'get_const'}}
+  // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
+  return (void *)0;
+}
+
+struct MyStruct {};
+
+const struct MyStruct get_struct() { // expected-warning{{no previous 
prototype for function 'get_struct'}}
+  // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
+  struct MyStruct ret;
+  return ret;
+}
+
+// Turn off clang-format for white-space dependent testing.
+// clang-format off
+// Two spaces between cost and struct
+const  struct MyStruct get_struct_2() {  // expected-warning{{no previous 
prototype for function 'get_struct_2'}}
+  // expected-note@-1{{declare 'static' if the function is not intended to be 
used outside of this translation unit}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
+  struct MyStruct ret;

[clang] 51401a6 - add isAtPosition narrowing matcher for parmVarDecl

2020-05-28 Thread Vy Nguyen via cfe-commits

Author: Vy Nguyen
Date: 2020-05-28T16:04:41-04:00
New Revision: 51401a676c036f2bd4e6b4b38f3538615799de40

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

LOG: add isAtPosition narrowing matcher for parmVarDecl

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index f57352389e4c..9db6795eb5fa 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -4671,6 +4671,23 @@ Narrowing Matchers
 Usable as: MatcherFunctionDecl>,
 MatcherVarDecl>,
 MatcherCXXRecordDecl>
 
 
+
+MatcherisAtPositionunsigned N
+Matches the 
ParmVarDecl nodes that are at the N'th position in the parameter
+list. The parameter list could be that of either a block, function, or
+objc-method.
+
+
+Given
+
+void f(int a, int b, int c) {
+}
+
+``parmVarDecl(isAtPosition(0))`` matches ``int a``.
+
+``parmVarDecl(isAtPosition(1))`` matches ``int b``.
+
+
 
 
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a750747c9aa3..a3747faa139c 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4257,6 +4257,34 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam,
   return Matched;
 }
 
+/// Matches the ParmVarDecl nodes that are at the N'th position in the 
parameter
+/// list. The parameter list could be that of either a block, function, or
+/// objc-method.
+///
+///
+/// Given
+///
+/// \code
+/// void f(int a, int b, int c) {
+/// }
+/// \endcode
+///
+/// ``parmVarDecl(isAtPosition(0))`` matches ``int a``.
+///
+/// ``parmVarDecl(isAtPosition(1))`` matches ``int b``.
+AST_MATCHER_P(clang::ParmVarDecl, isAtPosition, unsigned, N) {
+  const clang::DeclContext *Context = Node.getParentFunctionOrMethod();
+
+  if (const auto *Decl = dyn_cast_or_null(Context))
+return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
+  if (const auto *Decl = dyn_cast_or_null(Context))
+return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
+  if (const auto *Decl = dyn_cast_or_null(Context))
+return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
+
+  return false;
+}
+
 /// Matches any parameter of a function or an ObjC method declaration or a
 /// block.
 ///

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 0a7d09e55c88..14d9bbb3e52d 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -219,6 +219,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(floatLiteral);
   REGISTER_MATCHER(forEach);
   REGISTER_MATCHER(forEachArgumentWithParam);
+  REGISTER_MATCHER(isAtPosition);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
   REGISTER_MATCHER(forEachOverridden);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index a7d58528c0fb..929188abf6ac 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2643,6 +2643,45 @@ TEST(HasDefaultArgument, Basic) {
   parmVarDecl(hasDefaultArgument(;
 }
 
+TEST(IsAtPosition, Basic) {
+  EXPECT_TRUE(matches("void x(int a, int b) {}", 
parmVarDecl(isAtPosition(1;
+  EXPECT_TRUE(matches("void x(int a, int b) {}", 
parmVarDecl(isAtPosition(0;
+  EXPECT_TRUE(matches("void x(int a, int b) {}", 
parmVarDecl(isAtPosition(1;
+  EXPECT_TRUE(notMatches("void x(int val) {}", parmVarDecl(isAtPosition(1;
+}
+
+TEST(IsAtPosition, FunctionDecl) {
+  EXPECT_TRUE(matches("void x(int a);", parmVarDecl(isAtPosition(0;
+  EXPECT_TRUE(matches("void x(int a, int b);", parmVarDecl(isAtPosition(0;
+  EXPECT_TRUE(matches("void x(int a, int b);", parmVarDecl(isAtPosition(1;
+  EXPECT_TRUE(notMatches("void x(int val);", parmVarDecl(isAtPosition(1;
+}
+
+TEST(IsAtPosition, Lambda) {
+  EXPECT_TRUE(
+  matches("void x() { [](int a) {};  }", parmVarDecl(isAtPosition(0;
+  EXPECT_TRUE(matches("void x() { [](int a, int b) {}; }",
+  parmVarDecl(isAtPosition(0;
+  EXPECT_TRUE(m