[PATCH] D125840: [Analyzer] Removed extra space from NSErrorChecker debug message and updated relevant tests

2022-05-17 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125840

Files:
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/test/Analysis/CheckNSError.m


Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -27,7 +27,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning 
{{Method accepting NSError** should have a non-void return value to indicate 
whether or not an error occurred}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference. According to coding standards in 
'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
 }
 
 - (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
@@ -50,7 +50,7 @@
 typedef struct __CFError* CFErrorRef;
 
 void foo(CFErrorRef* error) { // expected-warning {{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred}}
-  *error = 0;  // expected-warning {{Potential null dereference}}
+  *error = 0;  // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
 int f1(CFErrorRef* error) {
@@ -74,7 +74,7 @@
 }
 
 int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
-  *error = 0; // expected-warning {{Potential null dereference}}
+  *error = 0; // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
   return 0;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -266,7 +266,7 @@
   SmallString<128> Buf;
   llvm::raw_svector_ostream os(Buf);
 
-  os << "Potential null dereference.  According to coding standards ";
+  os << "Potential null dereference. According to coding standards ";
   os << (isNSError
  ? "in 'Creating and Returning NSError Objects' the parameter"
  : "documented in CoreFoundation/CFError.h the parameter");


Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -27,7 +27,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference. According to coding standards in 'Creating and Returning NSError Objects' the parameter may be null [osx.cocoa.NSError]}}
 }
 
 - (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
@@ -50,7 +50,7 @@
 typedef struct __CFError* CFErrorRef;
 
 void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
-  *error = 0;  // expected-warning {{Potential null dereference}}
+  *error = 0;  // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
 }
 
 int f1(CFErrorRef* error) {
@@ -74,7 +74,7 @@
 }
 
 int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
-  *error = 0; // expected-warning {{Potential null dereference}}
+  *error = 0; // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
   return 0;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -266,7 +266,7 @@
   SmallString<128> Buf;
   llvm::raw_svector_ostream os(Buf);
 
-  os << "Potential null dereference.  According to coding stan

[PATCH] D125840: [Analyzer] Removed extra space from NSErrorChecker debug message and updated relevant tests

2022-05-18 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 430450.
usama54321 added a comment.

Updated tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125840/new/

https://reviews.llvm.org/D125840

Files:
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/test/Analysis/CheckNSError.m
  clang/test/Analysis/incorrect-checker-names.mm


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -107,7 +107,7 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0; // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
+  *error = 0; // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
 @interface A
@@ -116,7 +116,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {  // 
expected-warning {{Method accepting NSError** should have a non-void return 
value to indicate whether or not an error occurred [osx.cocoa.NSError]}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference.  According to coding standards 
in 'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference. According to coding standards in 
'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
 }
 @end
 
Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -27,7 +27,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning 
{{Method accepting NSError** should have a non-void return value to indicate 
whether or not an error occurred}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference. According to coding standards in 
'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
 }
 
 - (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
@@ -50,7 +50,7 @@
 typedef struct __CFError* CFErrorRef;
 
 void foo(CFErrorRef* error) { // expected-warning {{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred}}
-  *error = 0;  // expected-warning {{Potential null dereference}}
+  *error = 0;  // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
 int f1(CFErrorRef* error) {
@@ -74,7 +74,7 @@
 }
 
 int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
-  *error = 0; // expected-warning {{Potential null dereference}}
+  *error = 0; // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
   return 0;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -266,7 +266,7 @@
   SmallString<128> Buf;
   llvm::raw_svector_ostream os(Buf);
 
-  os << "Potential null dereference.  According to coding standards ";
+  os << "Potential null dereference. According to coding standards ";
   os << (isNSError
  ? "in 'Creating and Returning NSError Objects' the parameter"
  : "documented in CoreFoundation/CFError.h the parameter");


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -107,7 +107,7 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0; // expected-warning {{Potential null dereference.  According to codi

[PATCH] D125840: [Analyzer] Removed extra space from NSErrorChecker debug message and updated relevant tests

2022-05-18 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 430469.
usama54321 added a comment.

Fixed clang-format issue


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125840/new/

https://reviews.llvm.org/D125840

Files:
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/test/Analysis/CheckNSError.m
  clang/test/Analysis/incorrect-checker-names.mm


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -107,7 +107,7 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0; // expected-warning {{Potential null dereference.  According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
+  *error = 0; // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
 }
 
 @interface A
@@ -116,7 +116,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {  // 
expected-warning {{Method accepting NSError** should have a non-void return 
value to indicate whether or not an error occurred [osx.cocoa.NSError]}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference.  According to coding standards 
in 'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference. According to coding standards in 
'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
 }
 @end
 
Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -27,7 +27,7 @@
 
 @implementation A
 - (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning 
{{Method accepting NSError** should have a non-void return value to indicate 
whether or not an error occurred}}
-  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // 
expected-warning {{Potential null dereference. According to coding standards in 
'Creating and Returning NSError Objects' the parameter may be null 
[osx.cocoa.NSError]}}
 }
 
 - (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
@@ -50,7 +50,7 @@
 typedef struct __CFError* CFErrorRef;
 
 void foo(CFErrorRef* error) { // expected-warning {{Function accepting 
CFErrorRef* should have a non-void return value to indicate whether or not an 
error occurred}}
-  *error = 0;  // expected-warning {{Potential null dereference}}
+  *error = 0; // expected-warning {{Potential null 
dereference. According to coding standards documented in 
CoreFoundation/CFError.h the parameter may be null 
[osx.coreFoundation.CFError]}}
 }
 
 int f1(CFErrorRef* error) {
@@ -74,7 +74,7 @@
 }
 
 int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
-  *error = 0; // expected-warning {{Potential null dereference}}
+  *error = 0; // expected-warning {{Potential null dereference. According to 
coding standards documented in CoreFoundation/CFError.h the parameter may be 
null [osx.coreFoundation.CFError]}}
   return 0;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -266,7 +266,7 @@
   SmallString<128> Buf;
   llvm::raw_svector_ostream os(Buf);
 
-  os << "Potential null dereference.  According to coding standards ";
+  os << "Potential null dereference. According to coding standards ";
   os << (isNSError
  ? "in 'Creating and Returning NSError Objects' the parameter"
  : "documented in CoreFoundation/CFError.h the parameter");


Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -107,7 +107,7 @@
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0; // expected-warning {{Potential null dere

[PATCH] D126034: bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-19 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126034

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,7 +194,8 @@
   return nullptr;
 }
 
-bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ ASTContext &Context) {
   return selectFirst(
  NodeID::value,
  match(
@@ -225,6 +226,10 @@
  Stm, Context)) != nullptr;
 }
 
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+  return isUnevaluated(Exp, Stm, Context);
+}
+
 const Stmt *
 ExprMutationAnalyzer::findExprMutation(ArrayRef Matches) {
   return tryEachMatch(Matches, this, &ExprMutationAnalyzer::findMutation);
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ASTContext &Context);
 
 private:
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -650,3 +650,38 @@
   do {
   } while (1, (false) && val4 == 1);
 }
+
+void test_typeof() {
+  __typeof__({
+for (int i = 0; i < 10; ++i) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_infinite() {
+  __typeof__({
+for (int i = 0; i < 10;) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_while_infinite() {
+  __typeof__({
+int i = 0;
+while (i < 10) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_dowhile_infinite() {
+  __typeof__({
+int i = 0;
+do {
+
+} while (i < 10);
+0;
+  }) x;
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -81,6 +81,22 @@
   return false;
 }
 
+bool isUnevaluated(const Decl *Func, const Stmt *LoopStmt, const Stmt *Cond,
+   ASTContext *Context) {
+  if (const auto *Exp = dyn_cast(Cond)) {
+if (const auto *ForLoop = dyn_cast(LoopStmt)) {
+  return (ForLoop->getInc() && ExprMutationAnalyzer::isUnevaluated(
+   Exp, *ForLoop->getInc(), *Context)) ||
+ (ForLoop->getBody() && ExprMutationAnalyzer::isUnevaluated(
+Exp, *ForLoop->getBody(), *Context)) ||
+ (ForLoop->getCond() && ExprMutationAnalyzer::isUnevaluated(
+Exp, *ForLoop->getCond(), *Context));
+}
+return ExprMutationAnalyzer::isUnevaluated(Exp, *LoopStmt, *Context);
+  }
+  return true;
+}
+
 /// Return whether at least one variable of `Cond` changed in `LoopStmt`.
 static bool isAtLeastOneCondVarChanged(const Decl *Func, const Stmt *LoopStmt,
const Stmt *Cond, ASTContext *Context) {
@@ -177,6 +193,9 @@
 }
   }
 
+  if (isUnevaluated(Func, LoopStmt, Cond, Result.Context))
+return;
+
   if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126245: Added a separate check for unevaluated statements. Updated InfiniteLoopCheck to use new check

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126245

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,36 +194,44 @@
   return nullptr;
 }
 
+auto isUnevaluatedMatcher(const Stmt *Exp) {
+  return anyOf(
+  // `Exp` is part of the underlying expression of
+  // decltype/typeof if it has an ancestor of
+  // typeLoc.
+  hasAncestor(typeLoc(unless(hasAncestor(unaryExprOrTypeTraitExpr(),
+  hasAncestor(expr(anyOf(
+  // `UnaryExprOrTypeTraitExpr` is unevaluated
+  // unless it's sizeof on VLA.
+  unaryExprOrTypeTraitExpr(
+  unless(sizeOfExpr(hasArgumentOfType(variableArrayType(),
+  // `CXXTypeidExpr` is unevaluated unless it's
+  // applied to an expression of glvalue of
+  // polymorphic class type.
+  cxxTypeidExpr(unless(isPotentiallyEvaluated())),
+  // The controlling expression of
+  // `GenericSelectionExpr` is unevaluated.
+  genericSelectionExpr(
+  hasControllingExpr(hasDescendant(equalsNode(Exp,
+  cxxNoexceptExpr();
+}
+
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
  ASTContext &Context) {
-  return selectFirst(
+  return selectFirst(NodeID::value,
+   match(findAll(expr(canResolveToExpr(equalsNode(Exp)),
+  isUnevaluatedMatcher(Exp))
+ .bind(NodeID::value)),
+ Stm, Context)) != nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(
  NodeID::value,
- match(
- findAll(
- expr(canResolveToExpr(equalsNode(Exp)),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitExpr` is unevaluated
-  // unless it's sizeof on VLA.
-  unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
-  hasArgumentOfType(variableArrayType(),
-  // `CXXTypeidExpr` is unevaluated unless it's
-  // applied to an expression of glvalue of
-  // polymorphic class type.
-  cxxTypeidExpr(
-  unless(isPotentiallyEvaluated())),
-  // The controlling expression of
-  // `GenericSelectionExpr` is unevaluated.
-  genericSelectionExpr(hasControllingExpr(
-  hasDescendant(equalsNode(Exp,
-  cxxNoexceptExpr())
- .bind(NodeID::value)),
- Stm, Context)) != nullptr;
+ match(findAll(stmt(equalsNode(Exp), isUnevaluatedMatcher(Exp))
+   .bind(NodeID::value)),
+   Stm, Context)) != nullptr;
 }
 
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
+ASTContext &Context);
   static bool isUnevaluated(const Expr *Exp, const Stmt &Stm,
 ASTContext &Context);
 
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===

[PATCH] D126034: [clang-tidy] bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 431490.
usama54321 added a comment.

Added a separate check for unevaluated statements. Updated InfiniteLoopCheck to 
use new check


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126034/new/

https://reviews.llvm.org/D126034

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,36 +194,44 @@
   return nullptr;
 }
 
+auto isUnevaluatedMatcher(const Stmt *Exp) {
+  return anyOf(
+  // `Exp` is part of the underlying expression of
+  // decltype/typeof if it has an ancestor of
+  // typeLoc.
+  hasAncestor(typeLoc(unless(hasAncestor(unaryExprOrTypeTraitExpr(),
+  hasAncestor(expr(anyOf(
+  // `UnaryExprOrTypeTraitExpr` is unevaluated
+  // unless it's sizeof on VLA.
+  unaryExprOrTypeTraitExpr(
+  unless(sizeOfExpr(hasArgumentOfType(variableArrayType(),
+  // `CXXTypeidExpr` is unevaluated unless it's
+  // applied to an expression of glvalue of
+  // polymorphic class type.
+  cxxTypeidExpr(unless(isPotentiallyEvaluated())),
+  // The controlling expression of
+  // `GenericSelectionExpr` is unevaluated.
+  genericSelectionExpr(
+  hasControllingExpr(hasDescendant(equalsNode(Exp,
+  cxxNoexceptExpr();
+}
+
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
  ASTContext &Context) {
-  return selectFirst(
+  return selectFirst(NodeID::value,
+   match(findAll(expr(canResolveToExpr(equalsNode(Exp)),
+  isUnevaluatedMatcher(Exp))
+ .bind(NodeID::value)),
+ Stm, Context)) != nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(
  NodeID::value,
- match(
- findAll(
- expr(canResolveToExpr(equalsNode(Exp)),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitExpr` is unevaluated
-  // unless it's sizeof on VLA.
-  unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
-  hasArgumentOfType(variableArrayType(),
-  // `CXXTypeidExpr` is unevaluated unless it's
-  // applied to an expression of glvalue of
-  // polymorphic class type.
-  cxxTypeidExpr(
-  unless(isPotentiallyEvaluated())),
-  // The controlling expression of
-  // `GenericSelectionExpr` is unevaluated.
-  genericSelectionExpr(hasControllingExpr(
-  hasDescendant(equalsNode(Exp,
-  cxxNoexceptExpr())
- .bind(NodeID::value)),
- Stm, Context)) != nullptr;
+ match(findAll(stmt(equalsNode(Exp), isUnevaluatedMatcher(Exp))
+   .bind(NodeID::value)),
+   Stm, Context)) != nullptr;
 }
 
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
+ASTContext &Context);
   static bool isUnevaluated(const Expr *Exp, const Stmt &Stm,
 ASTContext &Context);
 
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
==

[PATCH] D126034: [clang-tidy] bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 431497.
usama54321 added a comment.

Updating patch


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126034/new/

https://reviews.llvm.org/D126034

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,35 +194,48 @@
   return nullptr;
 }
 
-bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
-  return selectFirst(
+auto isUnevaluatedMatcher(const Stmt *Exp) {
+  return anyOf(
+  // `Exp` is part of the underlying expression of
+  // decltype/typeof if it has an ancestor of
+  // typeLoc.
+  hasAncestor(typeLoc(unless(hasAncestor(unaryExprOrTypeTraitExpr(),
+  hasAncestor(expr(anyOf(
+  // `UnaryExprOrTypeTraitExpr` is unevaluated
+  // unless it's sizeof on VLA.
+  unaryExprOrTypeTraitExpr(
+  unless(sizeOfExpr(hasArgumentOfType(variableArrayType(),
+  // `CXXTypeidExpr` is unevaluated unless it's
+  // applied to an expression of glvalue of
+  // polymorphic class type.
+  cxxTypeidExpr(unless(isPotentiallyEvaluated())),
+  // The controlling expression of
+  // `GenericSelectionExpr` is unevaluated.
+  genericSelectionExpr(
+  hasControllingExpr(hasDescendant(equalsNode(Exp,
+  cxxNoexceptExpr();
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(NodeID::value,
+   match(findAll(expr(canResolveToExpr(equalsNode(Exp)),
+  isUnevaluatedMatcher(Exp))
+ .bind(NodeID::value)),
+ Stm, Context)) != nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(
  NodeID::value,
- match(
- findAll(
- expr(canResolveToExpr(equalsNode(Exp)),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitExpr` is unevaluated
-  // unless it's sizeof on VLA.
-  unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
-  hasArgumentOfType(variableArrayType(),
-  // `CXXTypeidExpr` is unevaluated unless it's
-  // applied to an expression of glvalue of
-  // polymorphic class type.
-  cxxTypeidExpr(
-  unless(isPotentiallyEvaluated())),
-  // The controlling expression of
-  // `GenericSelectionExpr` is unevaluated.
-  genericSelectionExpr(hasControllingExpr(
-  hasDescendant(equalsNode(Exp,
-  cxxNoexceptExpr())
- .bind(NodeID::value)),
- Stm, Context)) != nullptr;
+ match(findAll(stmt(equalsNode(Exp), isUnevaluatedMatcher(Exp))
+   .bind(NodeID::value)),
+   Stm, Context)) != nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+  return isUnevaluated(Exp, Stm, Context);
 }
 
 const Stmt *
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,10 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
+ASTContext &Context);
+  static bool isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ASTContext &

[PATCH] D126034: [clang-tidy] bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 431516.
usama54321 added a comment.

- updated canResolveToExpr to accept both statements and expressions. Removed 
unnecessary code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126034/new/

https://reviews.llvm.org/D126034

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -39,8 +39,13 @@
   return InnerMatcher.matches(*Result, Finder, Builder);
 }
 
-AST_MATCHER_P(Expr, canResolveToExpr, ast_matchers::internal::Matcher,
+AST_MATCHER_P(Stmt, canResolveToExpr, ast_matchers::internal::Matcher,
   InnerMatcher) {
+  auto *Exp = dyn_cast(&Node);
+  if (!Exp) {
+return stmt().matches(Node, Finder, Builder);
+  }
+
   auto DerivedToBase = [](const ast_matchers::internal::Matcher &Inner) {
 return implicitCastExpr(anyOf(hasCastKind(CK_DerivedToBase),
   hasCastKind(CK_UncheckedDerivedToBase)),
@@ -71,7 +76,7 @@
  IgnoreDerivedToBase(ConditionalOperator),
  IgnoreDerivedToBase(ElvisOperator;
 
-  return ComplexMatcher.matches(Node, Finder, Builder);
+  return ComplexMatcher.matches(*Exp, Finder, Builder);
 }
 
 // Similar to 'hasAnyArgument', but does not work because 'InitListExpr' does
@@ -194,12 +199,13 @@
   return nullptr;
 }
 
-bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
-  return selectFirst(
+bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(
  NodeID::value,
  match(
  findAll(
- expr(canResolveToExpr(equalsNode(Exp)),
+ stmt(canResolveToExpr(equalsNode(Exp)),
   anyOf(
   // `Exp` is part of the underlying expression of
   // decltype/typeof if it has an ancestor of
@@ -225,6 +231,10 @@
  Stm, Context)) != nullptr;
 }
 
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+  return isUnevaluated(Exp, Stm, Context);
+}
+
 const Stmt *
 ExprMutationAnalyzer::findExprMutation(ArrayRef Matches) {
   return tryEachMatch(Matches, this, &ExprMutationAnalyzer::findMutation);
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
+ASTContext &Context);
 
 private:
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -650,3 +650,38 @@
   do {
   } while (1, (false) && val4 == 1);
 }
+
+void test_typeof() {
+  __typeof__({
+for (int i = 0; i < 10; ++i) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_infinite() {
+  __typeof__({
+for (int i = 0; i < 10;) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_while_infinite() {
+  __typeof__({
+int i = 0;
+while (i < 10) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_dowhile_infinite() {
+  __typeof__({
+int i = 0;
+do {
+
+} while (i < 10);
+0;
+  }) x;
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -177,6 +177,9 @@
 }
   }
 
+  if (ExprMutationAnalyzer::isUnevaluated(LoopStmt, *LoopStmt, *Result.Context))
+return;
+
   if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126034: [clang-tidy] bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
usama54321 marked an inline comment as done.
Closed by commit rG602682225ad6: bugfix in InfiniteLoopCheck to not print 
warnings for unevaluated loops (authored by usama54321).

Changed prior to commit:
  https://reviews.llvm.org/D126034?vs=431516&id=431571#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126034/new/

https://reviews.llvm.org/D126034

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,7 +194,8 @@
   return nullptr;
 }
 
-bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ ASTContext &Context) {
   return selectFirst(
  NodeID::value,
  match(
@@ -225,6 +226,10 @@
  Stm, Context)) != nullptr;
 }
 
+bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
+  return isUnevaluated(Exp, Stm, Context);
+}
+
 const Stmt *
 ExprMutationAnalyzer::findExprMutation(ArrayRef Matches) {
   return tryEachMatch(Matches, this, &ExprMutationAnalyzer::findMutation);
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointeeMutation(const Expr *Exp);
   const Stmt *findPointeeMutation(const Decl *Dec);
+  static bool isUnevaluated(const Expr *Exp, const Stmt &Stm,
+ASTContext &Context);
 
 private:
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -650,3 +650,38 @@
   do {
   } while (1, (false) && val4 == 1);
 }
+
+void test_typeof() {
+  __typeof__({
+for (int i = 0; i < 10; ++i) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_infinite() {
+  __typeof__({
+for (int i = 0; i < 10;) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_while_infinite() {
+  __typeof__({
+int i = 0;
+while (i < 10) {
+}
+0;
+  }) x;
+}
+
+void test_typeof_dowhile_infinite() {
+  __typeof__({
+int i = 0;
+do {
+
+} while (i < 10);
+0;
+  }) x;
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -81,6 +81,22 @@
   return false;
 }
 
+bool isUnevaluated(const Decl *Func, const Stmt *LoopStmt, const Stmt *Cond,
+   ASTContext *Context) {
+  if (const auto *Exp = dyn_cast(Cond)) {
+if (const auto *ForLoop = dyn_cast(LoopStmt)) {
+  return (ForLoop->getInc() && ExprMutationAnalyzer::isUnevaluated(
+   Exp, *ForLoop->getInc(), *Context)) ||
+ (ForLoop->getBody() && ExprMutationAnalyzer::isUnevaluated(
+Exp, *ForLoop->getBody(), *Context)) ||
+ (ForLoop->getCond() && ExprMutationAnalyzer::isUnevaluated(
+Exp, *ForLoop->getCond(), *Context));
+}
+return ExprMutationAnalyzer::isUnevaluated(Exp, *LoopStmt, *Context);
+  }
+  return true;
+}
+
 /// Return whether at least one variable of `Cond` changed in `LoopStmt`.
 static bool isAtLeastOneCondVarChanged(const Decl *Func, const Stmt *LoopStmt,
const Stmt *Cond, ASTContext *Context) {
@@ -177,6 +193,9 @@
 }
   }
 
+  if (isUnevaluated(Func, LoopStmt, Cond, Result.Context))
+return;
+
   if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126246: bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops

2022-05-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
This revision was not accepted when it landed; it landed in state "Draft".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG63ecb7dcc80d: bugfix in InfiniteLoopCheck to not print 
warnings for unevaluated loops (authored by usama54321).
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D126246?vs=431496&id=431572#toc

Added a separate check for unevaluated statements. Updated InfiniteLoopCheck to 
use new check


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126246

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
  clang/lib/Analysis/ExprMutationAnalyzer.cpp

Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -194,36 +194,44 @@
   return nullptr;
 }
 
+auto isUnevaluatedMatcher(const Stmt *Exp) {
+  return anyOf(
+  // `Exp` is part of the underlying expression of
+  // decltype/typeof if it has an ancestor of
+  // typeLoc.
+  hasAncestor(typeLoc(unless(hasAncestor(unaryExprOrTypeTraitExpr(),
+  hasAncestor(expr(anyOf(
+  // `UnaryExprOrTypeTraitExpr` is unevaluated
+  // unless it's sizeof on VLA.
+  unaryExprOrTypeTraitExpr(
+  unless(sizeOfExpr(hasArgumentOfType(variableArrayType(),
+  // `CXXTypeidExpr` is unevaluated unless it's
+  // applied to an expression of glvalue of
+  // polymorphic class type.
+  cxxTypeidExpr(unless(isPotentiallyEvaluated())),
+  // The controlling expression of
+  // `GenericSelectionExpr` is unevaluated.
+  genericSelectionExpr(
+  hasControllingExpr(hasDescendant(equalsNode(Exp,
+  cxxNoexceptExpr();
+}
+
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp, const Stmt &Stm,
  ASTContext &Context) {
-  return selectFirst(
+  return selectFirst(NodeID::value,
+   match(findAll(expr(canResolveToExpr(equalsNode(Exp)),
+  isUnevaluatedMatcher(Exp))
+ .bind(NodeID::value)),
+ Stm, Context)) != nullptr;
+}
+
+bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Exp, const Stmt &Stm,
+ ASTContext &Context) {
+  return selectFirst(
  NodeID::value,
- match(
- findAll(
- expr(canResolveToExpr(equalsNode(Exp)),
-  anyOf(
-  // `Exp` is part of the underlying expression of
-  // decltype/typeof if it has an ancestor of
-  // typeLoc.
-  hasAncestor(typeLoc(unless(
-  hasAncestor(unaryExprOrTypeTraitExpr(),
-  hasAncestor(expr(anyOf(
-  // `UnaryExprOrTypeTraitExpr` is unevaluated
-  // unless it's sizeof on VLA.
-  unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
-  hasArgumentOfType(variableArrayType(),
-  // `CXXTypeidExpr` is unevaluated unless it's
-  // applied to an expression of glvalue of
-  // polymorphic class type.
-  cxxTypeidExpr(
-  unless(isPotentiallyEvaluated())),
-  // The controlling expression of
-  // `GenericSelectionExpr` is unevaluated.
-  genericSelectionExpr(hasControllingExpr(
-  hasDescendant(equalsNode(Exp,
-  cxxNoexceptExpr())
- .bind(NodeID::value)),
- Stm, Context)) != nullptr;
+ match(findAll(stmt(equalsNode(Exp), isUnevaluatedMatcher(Exp))
+   .bind(NodeID::value)),
+   Stm, Context)) != nullptr;
 }
 
 bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
Index: clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
===
--- clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -38,6 +38,8 @@
   }
   const Stmt *findPointe

[PATCH] D142243: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-24 Thread Usama Hameed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b6dbdecba0b: [CodeGen] bugfix: ApplyDebugLocation goes out 
of scope before intended (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142243/new/

https://reviews.llvm.org/D142243

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,14 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+
+@interface NSString
+@end
+
+struct A {
+NSString *a;
+};
+
+NSString* _Nonnull foo()
+{
+struct A a;
+return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,14 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+
+@interface NSString
+@end
+
+struct A {
+NSString *a;
+};
+
+NSString* _Nonnull foo()
+{
+struct A a;
+return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142421: [Sanitizers] fix -fno-sanitize-link-runtime for darwin

2023-02-01 Thread Usama Hameed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57690a8ece9e: [Sanitizers] fix -fno-sanitize-link-runtime 
for darwin (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142421/new/

https://reviews.llvm.org/D142421

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -25,6 +25,14 @@
 //
 // CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
+// RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-macosx -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan
+
 // RUN: %clang -fsanitize=address -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
@@ -288,6 +296,14 @@
 //
 // CHECK-TSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.tsan
 
+// RUN: %clang -fsanitize=thread -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-ios -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.tsan
+
 // RUN: %clangxx -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=memory \
@@ -353,6 +369,22 @@
 //
 // CHECK-UBSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.undefined
 
+// RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.ubsan
+
+// RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-watchos -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.fuzzer
+
 // RUN: %clang -fsanitize=undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1431,27 +1431,29 @@
 return;
   }
 
-  if (Sanitize.needsAsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
-  if (Sanitize.needsLsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
-  if (Sanitize.needsUbsanRt()) {
-assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
-AddLinkSanitizerLibArgs(Args, CmdArgs,
-Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-  : "ubsan");
-  }
-  if (Sanitize.needsTsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
-  if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
-AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
-
-// Libfuzzer is written in C++ and requires libcxx.
-AddCXXStdlibLibArgs(Args, CmdArgs);
-  }
-  if (Sanitize.needsStatsRt()) {
-AddLinkRuntimeLib(Args, CmdArgs, "stats_client", RLO_AlwaysLink);
-AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
+  if (Sanitize.linkRuntimes()) {
+if (Sanitize.needsAsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+if (Sanitize.needsLsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
+if (Sanitize.needsUbsanRt()) {
+  assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
+  AddLinkSanitizerLibArgs(Args, CmdArgs,
+  Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
+: "ubsan");
+}
+if (Sanitize.needsTsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
+if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
+
+// Libfuzzer is written in C++ and requires libcxx.
+AddCXX

[PATCH] D141550: [CompilerRT] Remove ubsan static runtime on Apple

2023-01-11 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a subscriber: Enna1.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added subscribers: Sanitizers, cfe-commits, MaskRay.
Herald added projects: clang, Sanitizers.

This patch removes the static ubsan runtime on Apple devices. The motivation
is to reduce the toolchain size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141550

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/ubsan/CMakeLists.txt
  compiler-rt/test/ubsan/CMakeLists.txt

Index: compiler-rt/test/ubsan/CMakeLists.txt
===
--- compiler-rt/test/ubsan/CMakeLists.txt
+++ compiler-rt/test/ubsan/CMakeLists.txt
@@ -101,7 +101,6 @@
 set(UBSAN_TEST_TARGET_ARCH ${arch})
 get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
 set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
-add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
   endforeach()
 
   # Device and simulator test suites.
Index: compiler-rt/lib/ubsan/CMakeLists.txt
===
--- compiler-rt/lib/ubsan/CMakeLists.txt
+++ compiler-rt/lib/ubsan/CMakeLists.txt
@@ -114,19 +114,21 @@
   LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
   PARENT_TARGET ubsan)
 
-add_compiler_rt_runtime(clang_rt.ubsan
-  STATIC
-  OS ${UBSAN_SUPPORTED_OS}
-  ARCHS ${UBSAN_SUPPORTED_ARCH}
-  OBJECT_LIBS RTUbsan
-  RTUbsan_standalone
-  RTSanitizerCommonNoHooks
-  RTSanitizerCommonLibcNoHooks
-  RTSanitizerCommonCoverage
-  RTSanitizerCommonSymbolizerNoHooks
-  RTInterception
-  LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
-  PARENT_TARGET ubsan)
+if (NOT APPLE)
+  add_compiler_rt_runtime(clang_rt.ubsan
+STATIC
+OS ${UBSAN_SUPPORTED_OS}
+ARCHS ${UBSAN_SUPPORTED_ARCH}
+OBJECT_LIBS RTUbsan
+RTUbsan_standalone
+RTSanitizerCommonNoHooks
+RTSanitizerCommonLibcNoHooks
+RTSanitizerCommonCoverage
+RTSanitizerCommonSymbolizerNoHooks
+RTInterception
+LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
+PARENT_TARGET ubsan)
+endif()
   endif()
 
 else()
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -423,8 +423,7 @@
 // RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}ld{{(.exe)?}}"
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}libclang_rt.ubsan_osx.a"
+// CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: Static UBSan runtime is not supported on darwin
 
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1425,6 +1425,12 @@
   }
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
+
+  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
+getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
+return;
+  }
+
   if (Sanitize.needsAsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
   if (Sanitize.needsLsanRt())
@@ -1432,8 +1438,7 @@
   if (Sanitize.needsUbsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs,
 Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-  : "ubsan",
-Sanitize.needsSharedRt());
+  : "ubsan");
   if (Sanitize.needsTsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
   if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -215,6 +215,8 @@
   "malformed sanitizer coverage allowlist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
+def err_drv_unsupported_static_ubsan_darwin : Error<
+  "Static UBSan runtime is not supported on darwin">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_

[PATCH] D141550: [CompilerRT] Remove ubsan static runtime on Apple

2023-01-11 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 488408.
usama54321 added a comment.

Addressing comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141550/new/

https://reviews.llvm.org/D141550

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/ubsan/CMakeLists.txt
  compiler-rt/test/ubsan/CMakeLists.txt

Index: compiler-rt/test/ubsan/CMakeLists.txt
===
--- compiler-rt/test/ubsan/CMakeLists.txt
+++ compiler-rt/test/ubsan/CMakeLists.txt
@@ -101,7 +101,6 @@
 set(UBSAN_TEST_TARGET_ARCH ${arch})
 get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
 set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
-add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
   endforeach()
 
   # Device and simulator test suites.
Index: compiler-rt/lib/ubsan/CMakeLists.txt
===
--- compiler-rt/lib/ubsan/CMakeLists.txt
+++ compiler-rt/lib/ubsan/CMakeLists.txt
@@ -114,19 +114,21 @@
   LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
   PARENT_TARGET ubsan)
 
-add_compiler_rt_runtime(clang_rt.ubsan
-  STATIC
-  OS ${UBSAN_SUPPORTED_OS}
-  ARCHS ${UBSAN_SUPPORTED_ARCH}
-  OBJECT_LIBS RTUbsan
-  RTUbsan_standalone
-  RTSanitizerCommonNoHooks
-  RTSanitizerCommonLibcNoHooks
-  RTSanitizerCommonCoverage
-  RTSanitizerCommonSymbolizerNoHooks
-  RTInterception
-  LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
-  PARENT_TARGET ubsan)
+if (NOT APPLE)
+  add_compiler_rt_runtime(clang_rt.ubsan
+STATIC
+OS ${UBSAN_SUPPORTED_OS}
+ARCHS ${UBSAN_SUPPORTED_ARCH}
+OBJECT_LIBS RTUbsan
+RTUbsan_standalone
+RTSanitizerCommonNoHooks
+RTSanitizerCommonLibcNoHooks
+RTSanitizerCommonCoverage
+RTSanitizerCommonSymbolizerNoHooks
+RTInterception
+LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
+PARENT_TARGET ubsan)
+endif()
   endif()
 
 else()
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -423,8 +423,7 @@
 // RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}ld{{(.exe)?}}"
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}libclang_rt.ubsan_osx.a"
+// CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1425,15 +1425,22 @@
   }
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
+
+  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
+getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
+return;
+  }
+
   if (Sanitize.needsAsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
   if (Sanitize.needsLsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
-  if (Sanitize.needsUbsanRt())
+  if (Sanitize.needsUbsanRt()) {
+assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
 AddLinkSanitizerLibArgs(Args, CmdArgs,
 Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-  : "ubsan",
-Sanitize.needsSharedRt());
+  : "ubsan");
+  }
   if (Sanitize.needsTsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
   if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -215,6 +215,8 @@
   "malformed sanitizer coverage allowlist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
+def err_drv_unsupported_static_ubsan_darwin : Error<
+  "static UndefinedBehaviorSanitizer runtime is not supported on darwin">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_c

[PATCH] D141550: [CompilerRT] Remove ubsan static runtime on Apple

2023-01-11 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 marked 3 inline comments as done.
usama54321 added inline comments.



Comment at: compiler-rt/lib/ubsan/CMakeLists.txt:118
+if (NOT APPLE)
+  add_compiler_rt_runtime(clang_rt.ubsan
+STATIC

delcypher wrote:
> I think you may have accidentally added tabs here when re-indenting.
I double checked and these are spaces :/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141550/new/

https://reviews.llvm.org/D141550

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


[PATCH] D141550: [CompilerRT] Remove ubsan static runtime on Apple

2023-01-11 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 marked an inline comment as done.
usama54321 added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:219
+def err_drv_unsupported_static_ubsan_darwin : Error<
+  "Static UBSan runtime is not supported on darwin">;
 def err_drv_duplicate_config : Error<

delcypher wrote:
> Nit: Driver messages start with lowercase.
> 
> Also please check if "UBSan" is spelt differently in existing driver 
> messages. It might actually be written more explicitly like "undefined 
> behavior sanitizer".
renamed UBSan to UndefinedBehaviorSanitizer as I see instances of 
AddressSanitizer and ThreadSanitizer in other messages. Did not find an 
equivalent for ubsan


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141550/new/

https://reviews.llvm.org/D141550

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


[PATCH] D141550: [CompilerRT] Remove ubsan static runtime on Apple

2023-01-17 Thread Usama Hameed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa44477b1f4b5: [CompilerRT] Remove ubsan static runtime on 
Apple (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141550/new/

https://reviews.llvm.org/D141550

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/ubsan/CMakeLists.txt
  compiler-rt/test/ubsan/CMakeLists.txt

Index: compiler-rt/test/ubsan/CMakeLists.txt
===
--- compiler-rt/test/ubsan/CMakeLists.txt
+++ compiler-rt/test/ubsan/CMakeLists.txt
@@ -101,7 +101,6 @@
 set(UBSAN_TEST_TARGET_ARCH ${arch})
 get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
 set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
-add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
   endforeach()
 
   # Device and simulator test suites.
Index: compiler-rt/lib/ubsan/CMakeLists.txt
===
--- compiler-rt/lib/ubsan/CMakeLists.txt
+++ compiler-rt/lib/ubsan/CMakeLists.txt
@@ -114,19 +114,21 @@
   LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
   PARENT_TARGET ubsan)
 
-add_compiler_rt_runtime(clang_rt.ubsan
-  STATIC
-  OS ${UBSAN_SUPPORTED_OS}
-  ARCHS ${UBSAN_SUPPORTED_ARCH}
-  OBJECT_LIBS RTUbsan
-  RTUbsan_standalone
-  RTSanitizerCommonNoHooks
-  RTSanitizerCommonLibcNoHooks
-  RTSanitizerCommonCoverage
-  RTSanitizerCommonSymbolizerNoHooks
-  RTInterception
-  LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
-  PARENT_TARGET ubsan)
+if (NOT APPLE)
+  add_compiler_rt_runtime(clang_rt.ubsan
+STATIC
+OS ${UBSAN_SUPPORTED_OS}
+ARCHS ${UBSAN_SUPPORTED_ARCH}
+OBJECT_LIBS RTUbsan
+RTUbsan_standalone
+RTSanitizerCommonNoHooks
+RTSanitizerCommonLibcNoHooks
+RTSanitizerCommonCoverage
+RTSanitizerCommonSymbolizerNoHooks
+RTInterception
+LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
+PARENT_TARGET ubsan)
+endif()
   endif()
 
 else()
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -423,8 +423,7 @@
 // RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}ld{{(.exe)?}}"
-// CHECK-UBSAN-STATIC-DARWIN: "{{.*}}libclang_rt.ubsan_osx.a"
+// CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1425,15 +1425,22 @@
   }
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
+
+  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
+getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
+return;
+  }
+
   if (Sanitize.needsAsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
   if (Sanitize.needsLsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
-  if (Sanitize.needsUbsanRt())
+  if (Sanitize.needsUbsanRt()) {
+assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
 AddLinkSanitizerLibArgs(Args, CmdArgs,
 Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-  : "ubsan",
-Sanitize.needsSharedRt());
+  : "ubsan");
+  }
   if (Sanitize.needsTsanRt())
 AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
   if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -215,6 +215,8 @@
   "malformed sanitizer coverage allowlist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_ignorelist : Error<
   "malformed sanitizer coverage ignorelist: '%0'">;
+def err_drv_unsupported_static_ubsan_darwin : Error<
+  "static UndefinedBehaviorSanitizer runtime is not 

[PATCH] D142242: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-20 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://103570533


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142242

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class GPUTraceShaderItem;
+
+@interface GPUCallgraphData : NSObject
+@end
+
+NSArray * _Nonnull 
GPUCallgraphDataItemsFromShaderItem(GPUTraceShaderItem *shaderItem)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class GPUTraceShaderItem;
+
+@interface GPUCallgraphData : NSObject
+@end
+
+NSArray * _Nonnull GPUCallgraphDataItemsFromShaderItem(GPUTraceShaderItem *shaderItem)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142242: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-20 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 490922.
usama54321 added a comment.

Renaming identifiers in test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142242/new/

https://reviews.llvm.org/D142242

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull GPUCallgraphDataItemsFromShaderItem(B* shaderItem)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull GPUCallgraphDataItemsFromShaderItem(B* shaderItem)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142242: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-20 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 490923.
usama54321 added a comment.

Renaming identifiers in test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142242/new/

https://reviews.llvm.org/D142242

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull foo(B* bar)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull foo(B* bar)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142243: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-20 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://103570533


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142243

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull foo(B* bar)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,17 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+#include 
+
+struct A {
+NSString *a;
+};
+
+@class B;
+
+@interface C: NSObject
+@end
+
+NSArray * _Nonnull foo(B* bar)
+{
+struct A a;
+return nil;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142243: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-20 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 490949.
usama54321 added a comment.

Removing unnecessary code from test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142243/new/

https://reviews.llvm.org/D142243

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,14 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc 
-std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+
+@interface NSString
+@end
+
+struct A {
+NSString *a;
+};
+
+NSString* _Nonnull foo()
+{
+struct A a;
+return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);


Index: clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-arc-ubsan-debugging.m
@@ -0,0 +1,14 @@
+// RUN: %clang -x objective-c -target arm64-apple-macos12.0 -fobjc-arc -std=gnu99  -O0 -fsanitize=undefined -fsanitize=nullability -c %s -v -g
+
+@interface NSString
+@end
+
+struct A {
+NSString *a;
+};
+
+NSString* _Nonnull foo()
+{
+struct A a;
+return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -361,17 +361,18 @@
   bool HasOnlyLifetimeMarkers =
   HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
   bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
+
+  std::optional OAL;
   if (HasCleanups) {
 // Make sure the line table doesn't jump back into the body for
 // the ret after it's been at EndLoc.
-std::optional AL;
 if (CGDebugInfo *DI = getDebugInfo()) {
   if (OnlySimpleReturnStmts)
 DI->EmitLocation(Builder, EndLoc);
   else
 // We may not have a valid end location. Try to apply it anyway, and
 // fall back to an artificial location if needed.
-AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+OAL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
 }
 
 PopCleanupBlocks(PrologueCleanupDepth);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142243: [CodeGen] bugfix: ApplyDebugLocation goes out of scope before intended

2023-01-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added a comment.

The libcxx test failure seems unrelated and seems to be failing on master
https://buildkite.com/llvm-project/libcxx-ci/builds?branch=master


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142243/new/

https://reviews.llvm.org/D142243

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


[PATCH] D142421: [Sanitizers] fix -fno-sanitize-link-runtime for darwin

2023-01-23 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

rdar://99200922


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142421

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -25,6 +25,14 @@
 //
 // CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
+// RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-macosx -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan
+
 // RUN: %clang -fsanitize=address -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
@@ -288,6 +296,14 @@
 //
 // CHECK-TSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.tsan
 
+// RUN: %clang -fsanitize=thread -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-ios -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.tsan
+
 // RUN: %clangxx -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=memory \
@@ -353,6 +369,22 @@
 //
 // CHECK-UBSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.undefined
 
+// RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.ubsan
+
+// RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: --target=arm64e-apple-watchos -fuse-ld=ld \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN %s
+//
+// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.fuzzer
+
 // RUN: %clang -fsanitize=undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1431,27 +1431,29 @@
 return;
   }
 
-  if (Sanitize.needsAsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
-  if (Sanitize.needsLsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
-  if (Sanitize.needsUbsanRt()) {
-assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
-AddLinkSanitizerLibArgs(Args, CmdArgs,
-Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-  : "ubsan");
-  }
-  if (Sanitize.needsTsanRt())
-AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
-  if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
-AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
-
-// Libfuzzer is written in C++ and requires libcxx.
-AddCXXStdlibLibArgs(Args, CmdArgs);
-  }
-  if (Sanitize.needsStatsRt()) {
-AddLinkRuntimeLib(Args, CmdArgs, "stats_client", RLO_AlwaysLink);
-AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
+  if (Sanitize.linkRuntimes()) {
+if (Sanitize.needsAsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+if (Sanitize.needsLsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
+if (Sanitize.needsUbsanRt()) {
+  assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
+  AddLinkSanitizerLibArgs(Args, CmdArgs,
+  Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
+: "ubsan");
+}
+if (Sanitize.needsTsanRt())
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
+if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
+
+// Libfuzzer is written in C++ and requires libcxx.
+AddCXXStdlibLibArgs(Args, CmdArgs);
+}
+if (Sanitize.needsStatsRt()) {
+  AddLinkRuntimeLib(Args, Cm

[PATCH] D157445: [CodeGen][UBSan] Add support for handling attributed functions in getUBSanFunctionTypeHash.

2023-08-15 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 550475.
usama54321 retitled this revision from "[CodeGen][UBSan] Add support for 
handling attributed functions in getUBSanFunctionTypeHash." to 
"[CodeGen][UBSan] Add support for handling attributed functions in 
getUBSanFunctionTypeHash.".
usama54321 added a comment.

Updated PR according to feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157445/new/

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long905068220
+void g(void) {}
+
+// CHECK: .long1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long	248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long	905068220
+void g(void) {}
+
+// CHECK: .long	1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long	1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157445: [CodeGen][UBSan] Add support for handling attributed functions in getUBSanFunctionTypeHash.

2023-08-15 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 550477.
usama54321 added a comment.

Updated commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157445/new/

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long905068220
+void g(void) {}
+
+// CHECK: .long1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long	248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long	905068220
+void g(void) {}
+
+// CHECK: .long	1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long	1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157445: [CodeGen][UBSan] Add support for handling attributed functions in getUBSanFunctionTypeHash.

2023-08-16 Thread Usama Hameed via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9afc57dcb2e5: [CodeGen][UBSan] Handle sugared QualTypes 
correctly in (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157445/new/

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long905068220
+void g(void) {}
+
+// CHECK: .long1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | FileCheck %s --check-prefixes=CHECK
+
+// CHECK: .long	248076293
+void __attribute__((ms_abi)) f(void) {}
+
+// CHECK: .long	905068220
+void g(void) {}
+
+// CHECK: .long	1717976574
+void __attribute__((ms_abi)) f_no_prototype() {}
+
+// CHECK: .long	1717976574
+void g_no_prototype() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -572,7 +572,7 @@
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
-  if (!isa(Ty))
+  if (!Ty->isFunctionNoProtoType())
 Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
   std::string Mangled;
   llvm::raw_string_ostream Out(Mangled);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157445: [CodeGen][UBSan] getUBSanFunctionTypeHash does not handle the attributed function case correctly, leading to an assertion failure. This patch desugars the QualType if it is of Attribu

2023-08-08 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 created this revision.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://113144087


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s 
-o /dev/null
+
+long __attribute__((ms_abi)) f() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -570,6 +570,9 @@
 
 llvm::ConstantInt *
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
+  if (isa(Ty))
+Ty = Ty.getDesugaredType(getContext());
+
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
   if (!isa(Ty))


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s -o /dev/null
+
+long __attribute__((ms_abi)) f() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -570,6 +570,9 @@
 
 llvm::ConstantInt *
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
+  if (isa(Ty))
+Ty = Ty.getDesugaredType(getContext());
+
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
   if (!isa(Ty))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157445: [CodeGen][UBSan] getUBSanFunctionTypeHash does not handle the attributed function case correctly, leading to an assertion failure. This patch desugars the QualType if it is of Attribu

2023-08-09 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 updated this revision to Diff 548723.
usama54321 added a comment.

Fix commit message and description, and added comment explaining the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157445/new/

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s 
-o /dev/null
+
+//Make sure compiler does not crash inside getUBSanFunctionTypeHash while 
compiling this
+long __attribute__((ms_abi)) f() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -570,6 +570,9 @@
 
 llvm::ConstantInt *
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
+  if (isa(Ty))
+Ty = Ty.getDesugaredType(getContext());
+
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
   if (!isa(Ty))


Index: clang/test/CodeGen/ubsan-function-attributed.c
===
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s -o /dev/null
+
+//Make sure compiler does not crash inside getUBSanFunctionTypeHash while compiling this
+long __attribute__((ms_abi)) f() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -570,6 +570,9 @@
 
 llvm::ConstantInt *
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
+  if (isa(Ty))
+Ty = Ty.getDesugaredType(getContext());
+
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
   if (!isa(Ty))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-02-28 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 accepted this revision.
usama54321 added a comment.
This revision is now accepted and ready to land.

I was verifying that static versions of these libraries are not present on 
darwin. Sorry for the delay.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Usama Hameed via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e7d40e0928c: [Sanitizers] Error out for -static-libsan on 
darwin (authored by usama54321).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
 // CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
+// RUN: %clang -fsanitize=address -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-STATIC-DARWIN %s
+// CHECK-ASAN-STATIC-DARWIN: {{.*}}error: static AddressSanitizer runtime is not supported on darwin
+
+// RUN: %clang -fsanitize=thread -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TSAN-STATIC-DARWIN %s
+// CHECK-TSAN-STATIC-DARWIN: {{.*}}error: static ThreadSanitizer runtime is not supported on darwin
+
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  if (!Sanitize.needsSharedRt()) {
+const char *sanitizer = nullptr;
+if (Sanitize.needsUbsanRt()) {
+  sanitizer = "UndefinedBehaviorSanitizer";
+} else if (Sanitize.needsAsanRt()) {
+  sanitizer = "AddressSanitizer";
+} else if (Sanitize.needsTsanRt()) {
+  sanitizer = "ThreadSanitizer";
+}
+if (sanitizer) {
+  getDriver().Diag(diag::err_drv_unsupported_static_sanitizer_darwin)
+  << sanitizer;
+  return;
+}
   }
 
   if (Sanitize.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+}
 if (Sanitize.needsLsanRt())
   AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
 if (Sanitize.needsUbsanRt()) {
-  assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
-  AddLinkSanitizerLibArgs(Args, CmdArgs,
-  Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
-: "ubsan");
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
+  AddLinkSanitizerLibArgs(
+  Args, CmdArgs,
+  Sanitize.requiresMinimalRuntime() ? "ubsan_minimal" : "ubsan");
 }
-if (Sanitize.needsTsanRt())
+if (Sanitize.needsTsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
   AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
+}
 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
   AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1215,7 +1215,7 @@
 def shared_libsan : Flag<["-"], "shared-libsan">,
   HelpText<"Dynamically link the sanitizer runtime">;
 def static_libsan : Flag<["-"], "static-libsan">,
-  HelpText<"Statically link the sanitizer runtime">;
+  HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias;
 def fasm : Flag<["-"], "fasm">, Group;
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -220,8 +220,8 @@
   "malformed sanitizer coverage ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_metadata_ignorelist : Erro

[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-01 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 reopened this revision.
usama54321 added a comment.
This revision is now accepted and ready to land.

@dmaclach Can you please take a look and fix this? Thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-02 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added a comment.

I have reverted the commit for now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> zixuw wrote:
> > dmaclach wrote:
> > > yln wrote:
> > > > This should work, right?
> > > No.. darwin should fail with the `-static-libsan` flag. This is the test 
> > > that was failing and caused the rollback.
> > I think @yln is suggesting using `REQUIRES: asan-static-runtime` instead of 
> > `XFAIL: darwin`. I wasn't aware of that conditional but yeah that should be 
> > better if it works.
> I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: darwin` 
> since it seems that we already have a lit feature for it.
I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
understands that REQUIRES: asan-static-runtime should result in skipping the 
test on Darwin as it does not know about this dependency.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-03 Thread Usama Hameed via Phabricator via cfe-commits
usama54321 added inline comments.



Comment at: 
compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp:10-11
+
+// darwin only supports shared-libsan, so this should fail.
+// XFAIL: darwin
+ 

yln wrote:
> usama54321 wrote:
> > yln wrote:
> > > zixuw wrote:
> > > > dmaclach wrote:
> > > > > yln wrote:
> > > > > > This should work, right?
> > > > > No.. darwin should fail with the `-static-libsan` flag. This is the 
> > > > > test that was failing and caused the rollback.
> > > > I think @yln is suggesting using `REQUIRES: asan-static-runtime` 
> > > > instead of `XFAIL: darwin`. I wasn't aware of that conditional but yeah 
> > > > that should be better if it works.
> > > I meant using `// REQUIRES: asan-static-runtime ` instead of `XFAIL: 
> > > darwin` since it seems that we already have a lit feature for it.
> > I think UNSUPPORTED: darwin makes the most sense here. I don't think lit 
> > understands that REQUIRES: asan-static-runtime should result in skipping 
> > the test on Darwin as it does not know about this dependency.
> > I don't think lit understands that REQUIRES: asan-static-runtime should 
> > result in skipping the test on Darwin as it does not know about this 
> > dependency.
> 
> Actually, this was exactly my point.  We have other tests already marked with 
> `REQUIRES: asan-static-runtime` and we should double check our changes don't 
> affect these as well.
> 
> If LIT doesn't model this dependency yet, then we should make sure it does!  
> And this test can act as a good "canary in the coal mine".
> 
> Please use `REQUIRES: asan-static-runtime` and make sure we understand and 
> deal with any fallout.
Sorry for my earlier comment. @yln is correct, and we should use REQUIRES: 
asan-static-runtime. I double checked, and this already works as expected on 
darwin, i.e. these tests are unsupported on darwin. So you should not need to 
do anything apart from adding the REQUIRES in the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

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


[PATCH] D144672: [Sanitizers] Error when attempting to use `static-lsan` with `TSan` or `Asan` on darwin

2023-03-06 Thread Usama Hameed via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG665e32ee0ffd: [Sanitizers] Error out for -static-libsan on 
darwin (authored by usama54321).

Changed prior to commit:
  https://reviews.llvm.org/D144672?vs=502474&id=502569#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144672/new/

https://reviews.llvm.org/D144672

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/asan/TestCases/replaceable_new_delete.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
  compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp

Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_static.cpp
@@ -1,11 +1,13 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using static-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
 // the new/delete interceptors as "weak" using those workarounds as well.
 // UNSUPPORTED: target={{.*windows.*}}
 
-// RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
+// darwin only supports `shared-libsan`.
+// REQUIRES: asan-static-runtime
+
 // RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
Index: compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
===
--- compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
+++ compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp
@@ -1,4 +1,4 @@
-// Ensure that operator new/delete are still replaceable.
+// Ensure that operator new/delete are still replaceable using shared-libsan.
 
 // FIXME: Weak symbols aren't supported on Windows, although some code in
 // compiler-rt already exists to solve this problem. We should probably define
@@ -6,7 +6,6 @@
 // UNSUPPORTED: target={{.*windows.*}}
 
 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s
 
 #include 
 #include 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -457,6 +457,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-STATIC-DARWIN %s
 // CHECK-UBSAN-STATIC-DARWIN: {{.*}}error: static UndefinedBehaviorSanitizer runtime is not supported on darwin
 
+// RUN: %clang -fsanitize=address -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-STATIC-DARWIN %s
+// CHECK-ASAN-STATIC-DARWIN: {{.*}}error: static AddressSanitizer runtime is not supported on darwin
+
+// RUN: %clang -fsanitize=thread -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin -fuse-ld=ld -static-libsan \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TSAN-STATIC-DARWIN %s
+// CHECK-TSAN-STATIC-DARWIN: {{.*}}error: static ThreadSanitizer runtime is not supported on darwin
+
 // RUN: %clang -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1426,24 +1426,42 @@
 
   const SanitizerArgs &Sanitize = getSanitizerArgs(Args);
 
-  if (!Sanitize.needsSharedRt() && Sanitize.needsUbsanRt()) {
-getDriver().Diag(diag::err_drv_unsupported_static_ubsan_darwin);
-return;
+  if (!Sanitize.needsSharedRt()) {
+const char *sanitizer = nullptr;
+if (Sanitize.needsUbsanRt()) {
+  sanitizer = "UndefinedBehaviorSanitizer";
+} else if (Sanitize.needsAsanRt()) {
+  sanitizer = "AddressSanitizer";
+} else if (Sanitize.needsTsanRt()) {
+  sanitizer = "ThreadSanitizer";
+}
+if (sanitizer) {
+  getDriver().Diag(diag::err_drv_unsupported_static_sanitizer_darwin)
+  << sanitizer;
+  return;
+}
   }
 
   if (Sanitize.linkRuntimes()) {
-if (Sanitize.needsAsanRt())
+if (Sanitize.needsAsanRt()) {
+  assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");