[PATCH] D57072: Don't codegen an unreachable return block

2019-01-22 Thread Brad Moody via Phabricator via cfe-commits
bmoody created this revision.
bmoody added reviewers: craig.topper, dberris, rjmccall.
Herald added a subscriber: cfe-commits.

This patch adds a check at the end of CodeGenFunction::FinishFunction to delete 
the return block if it isn't reachable.

Without this patch applied the code generated for the test cases is:

define void @f1() {
entry:

  call void @abort()
  unreachable

return:   ; No predecessors!

  ret void

}

define i8* @f2() {
entry:

  %retval = alloca i8*, align 8
  call void @abort()
  unreachable

return:   ; No predecessors!

  %0 = load i8*, i8** %retval, align 8
  ret i8* %0

}

This sort-of addresses the FIXME in CodeGenFunction::EmitReturnBlock:

  // FIXME: We are at an unreachable point, there is no reason to emit the block
  // unless it has uses. However, we still need a place to put the debug
  // region.end for now.

I'm not sure if this FIXME still applies with this patch - it's not clear if 
the intent is to avoid generating the unreachable code in the first place, 
rather than generating it and then deleting it.  Seems like it would complicate 
the rest of the codegen to avoid generating it in the first place.


Repository:
  rC Clang

https://reviews.llvm.org/D57072

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/unreachable-ret.c
  test/OpenMP/parallel_reduction_codegen.cpp

Index: test/OpenMP/parallel_reduction_codegen.cpp
===
--- test/OpenMP/parallel_reduction_codegen.cpp
+++ test/OpenMP/parallel_reduction_codegen.cpp
@@ -622,7 +622,7 @@
 
 // CHECK-NOT: call i32 @__kmpc_reduce
 
-// CHECK: ret void
+// CHECK: }
 
 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
Index: test/CodeGen/unreachable-ret.c
===
--- /dev/null
+++ test/CodeGen/unreachable-ret.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+extern void abort() __attribute__((noreturn));
+
+void f1() {
+  abort();
+}
+// CHECK-LABEL: define void @f1()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   call void @abort()
+// CHECK-NEXT:   unreachable
+// CHECK-NEXT: }
+
+void *f2() {
+  abort();
+  return 0;
+}
+// CHECK-LABEL: define i8* @f2()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   call void @abort()
+// CHECK-NEXT:   unreachable
+// CHECK-NEXT: }
+
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -255,6 +255,7 @@
 if (CurBB->empty() || ReturnBlock.getBlock()->use_empty()) {
   ReturnBlock.getBlock()->replaceAllUsesWith(CurBB);
   delete ReturnBlock.getBlock();
+  ReturnBlock = JumpDest();
 } else
   EmitBlock(ReturnBlock.getBlock());
 return llvm::DebugLoc();
@@ -274,6 +275,7 @@
   Builder.SetInsertPoint(BI->getParent());
   BI->eraseFromParent();
   delete ReturnBlock.getBlock();
+  ReturnBlock = JumpDest();
   return Loc;
 }
   }
@@ -448,6 +450,19 @@
   // 5. Width of vector aguments and return types for functions called by this
   //function.
   CurFn->addFnAttr("min-legal-vector-width", llvm::utostr(LargestVectorWidth));
+
+  // If we generated an unreachable return block, delete it now.
+  if (ReturnBlock.isValid() && ReturnBlock.getBlock()->use_empty()) {
+Builder.ClearInsertionPoint();
+ReturnBlock.getBlock()->eraseFromParent();
+  }
+  if (ReturnValue.isValid()) {
+auto *RetAlloca = dyn_cast(ReturnValue.getPointer());
+if (RetAlloca && RetAlloca->use_empty()) {
+  RetAlloca->eraseFromParent();
+  ReturnValue = Address::invalid();
+}
+  }
 }
 
 /// ShouldInstrumentFunction - Return true if the current function should be
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -2896,15 +2896,6 @@
 RV = SI->getValueOperand();
 SI->eraseFromParent();
 
-// If that was the only use of the return value, nuke it as well now.
-auto returnValueInst = ReturnValue.getPointer();
-if (returnValueInst->use_empty()) {
-  if (auto alloca = dyn_cast(returnValueInst)) {
-alloca->eraseFromParent();
-ReturnValue = Address::invalid();
-  }
-}
-
   // Otherwise, we have to do a simple load.
   } else {
 RV = Builder.CreateLoad(ReturnValue);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57072: Don't codegen an unreachable return block

2019-01-23 Thread Brad Moody via Phabricator via cfe-commits
bmoody added a comment.

Great, I don't have commit access so you're welcome to commit on my behalf.  
Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D57072



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


[PATCH] D57072: Don't codegen an unreachable return block

2019-03-25 Thread Brad Moody via Phabricator via cfe-commits
bmoody added a comment.
Herald added a subscriber: jdoerfert.
Herald added a project: clang.

Ping! Any chance you could commit this on my behalf? Otherwise I can try the 
mailing list.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57072



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


[PATCH] D60997: Fix unquoted spaces in args in clang --verbose output

2019-04-23 Thread Brad Moody via Phabricator via cfe-commits
bmoody created this revision.
bmoody added a reviewer: hans.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The behaviour of not quoting spaces appears to have been introduced by mistake 
in revision b212b34f19472469c1d20ada3161c3523268d5be 



Repository:
  rC Clang

https://reviews.llvm.org/D60997

Files:
  clang/lib/Driver/Job.cpp
  clang/test/Driver/verbose-output-quoting.c


Index: clang/test/Driver/verbose-output-quoting.c
===
--- /dev/null
+++ clang/test/Driver/verbose-output-quoting.c
@@ -0,0 +1,9 @@
+// RUN: %clang --verbose -DSPACE="a b"  -c %s 2>&1 | FileCheck 
-check-prefix=SPACE -strict-whitespace %s
+// RUN: %clang --verbose -DQUOTES=\"\"  -c %s 2>&1 | FileCheck 
-check-prefix=QUOTES-strict-whitespace %s
+// RUN: %clang --verbose -DBACKSLASH=\\ -c %s 2>&1 | FileCheck 
-check-prefix=BACKSLASH -strict-whitespace %s
+// RUN: %clang --verbose -DDOLLAR=\$-c %s 2>&1 | FileCheck 
-check-prefix=DOLLAR-strict-whitespace %s
+
+// SPACE: -cc1 {{.*}} -D "SPACE=a b"
+// QUOTES: -cc1 {{.*}} -D "QUOTES=\"\""
+// BACKSLASH: -cc1 {{.*}} -D "BACKSLASH=\\"
+// DOLLAR: -cc1 {{.*}} -D "DOLLAR=\$"
Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -99,7 +99,7 @@
 }
 
 void Command::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
-  const bool Escape = Arg.find_first_of("\"\\$") != StringRef::npos;
+  const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos;
 
   if (!Quote && !Escape) {
 OS << Arg;


Index: clang/test/Driver/verbose-output-quoting.c
===
--- /dev/null
+++ clang/test/Driver/verbose-output-quoting.c
@@ -0,0 +1,9 @@
+// RUN: %clang --verbose -DSPACE="a b"  -c %s 2>&1 | FileCheck -check-prefix=SPACE -strict-whitespace %s
+// RUN: %clang --verbose -DQUOTES=\"\"  -c %s 2>&1 | FileCheck -check-prefix=QUOTES-strict-whitespace %s
+// RUN: %clang --verbose -DBACKSLASH=\\ -c %s 2>&1 | FileCheck -check-prefix=BACKSLASH -strict-whitespace %s
+// RUN: %clang --verbose -DDOLLAR=\$-c %s 2>&1 | FileCheck -check-prefix=DOLLAR-strict-whitespace %s
+
+// SPACE: -cc1 {{.*}} -D "SPACE=a b"
+// QUOTES: -cc1 {{.*}} -D "QUOTES=\"\""
+// BACKSLASH: -cc1 {{.*}} -D "BACKSLASH=\\"
+// DOLLAR: -cc1 {{.*}} -D "DOLLAR=\$"
Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -99,7 +99,7 @@
 }
 
 void Command::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
-  const bool Escape = Arg.find_first_of("\"\\$") != StringRef::npos;
+  const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos;
 
   if (!Quote && !Escape) {
 OS << Arg;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60997: Fix unquoted spaces in args in clang --verbose output

2019-04-23 Thread Brad Moody via Phabricator via cfe-commits
bmoody added a comment.

I don't have commit access, so you are welcome to commit on my behalf.  Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D60997



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


[PATCH] D52855: Fix source loc for tokens that immediately follow an escaped newline

2018-10-03 Thread Brad Moody via Phabricator via cfe-commits
bmoody created this revision.
bmoody added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

Previously the location of a token immediately following an escaped newline was 
the location of the backslash character in the escaped newline.

The change to test/SemaTemplate/instantiation-depth.cpp is to work around a 
side-effect of this fix - the expected-error comment was getting the location 
of the backslash on the previous line before. I added the extra slashes so that 
the comment starts on the correct line.


Repository:
  rC Clang

https://reviews.llvm.org/D52855

Files:
  lib/Lex/Lexer.cpp
  test/Misc/escaped-newline-loc.c
  test/SemaTemplate/instantiation-depth.cpp


Index: test/SemaTemplate/instantiation-depth.cpp
===
--- test/SemaTemplate/instantiation-depth.cpp
+++ test/SemaTemplate/instantiation-depth.cpp
@@ -4,7 +4,7 @@
 
 #ifndef NOEXCEPT
 
-template struct X : X { }; \
+template struct X : X { }; // \
 // expected-error{{recursive template instantiation exceeded maximum depth of 
5}} \
 // expected-note 3 {{instantiation of template class}} \
 // expected-note {{skipping 2 contexts in backtrace}} \
@@ -19,7 +19,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 
-ftemplate-backtrace-limit 4 -std=c++11 -DNOEXCEPT %s
 
 template struct S {
-  S() noexcept(noexcept(S())); \
+  S() noexcept(noexcept(S())); // \
 // expected-error{{recursive template instantiation exceeded maximum depth of 
5}} \
 // expected-note 3 {{in instantiation of exception spec}} \
 // expected-note {{skipping 2 contexts in backtrace}} \
Index: test/Misc/escaped-newline-loc.c
===
--- /dev/null
+++ test/Misc/escaped-newline-loc.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Wno-backslash-newline-escape
+
+// Test that the location of a token that immediately follows an escaped
+// newline is correct, and doesn't point to the backslash
+
+void f() {
+  \
+error1; // expected-error {{use of undeclared identifier 'error1'}}
+
+  // Escaped newline with space
+  \ 
+error2; // expected-error {{use of undeclared identifier 'error2'}}
+
+  // Escaped newline with two spaces
+  \  
+error3; // expected-error {{use of undeclared identifier 'error3'}}
+}
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3193,6 +3193,17 @@
 
   // Read a character, advancing over it.
   char Char = getAndAdvanceChar(CurPtr, Result);
+
+  // If we had to skip over an escaped newline to get this character then
+  // update BufferPtr to point to the character we got, instead of pointing
+  // at the backslash. This fixes the source location for tokens that
+  // immediately follow an escaped newline.
+  if (!isKeepWhitespaceMode() &&
+  Result.needsCleaning() && CurPtr[-1] == Char) {
+Result.clearFlag(Token::NeedsCleaning);
+BufferPtr = CurPtr - 1;
+  }
+
   tok::TokenKind Kind;
 
   switch (Char) {


Index: test/SemaTemplate/instantiation-depth.cpp
===
--- test/SemaTemplate/instantiation-depth.cpp
+++ test/SemaTemplate/instantiation-depth.cpp
@@ -4,7 +4,7 @@
 
 #ifndef NOEXCEPT
 
-template struct X : X { }; \
+template struct X : X { }; // \
 // expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
 // expected-note 3 {{instantiation of template class}} \
 // expected-note {{skipping 2 contexts in backtrace}} \
@@ -19,7 +19,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 -std=c++11 -DNOEXCEPT %s
 
 template struct S {
-  S() noexcept(noexcept(S())); \
+  S() noexcept(noexcept(S())); // \
 // expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
 // expected-note 3 {{in instantiation of exception spec}} \
 // expected-note {{skipping 2 contexts in backtrace}} \
Index: test/Misc/escaped-newline-loc.c
===
--- /dev/null
+++ test/Misc/escaped-newline-loc.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Wno-backslash-newline-escape
+
+// Test that the location of a token that immediately follows an escaped
+// newline is correct, and doesn't point to the backslash
+
+void f() {
+  \
+error1; // expected-error {{use of undeclared identifier 'error1'}}
+
+  // Escaped newline with space
+  \ 
+error2; // expected-error {{use of undeclared identifier 'error2'}}
+
+  // Escaped newline with two spaces
+  \  
+error3; // expected-error {{use of undeclared identifier 'error3'}}
+}
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3193,6 +3193,17 @@
 
   // Read a character, advancing over it.
   char Char = getAndAdvanceChar(CurPtr, Result);
+
+  // If we had to ski

[PATCH] D65913: Fix segfault caused by the "libstdc++ eager exception spec hack"

2019-08-07 Thread Brad Moody via Phabricator via cfe-commits
bmoody created this revision.
bmoody added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Segfault occurs when the hack is applied to a function decl containing
an unparsed default argument. Parser::HandleMemberFunctionDeclDelays
was assuming that if a decl contains an unparsed default arg then it
must also have an unparsed exception spec. This causes a
read-from-wrong-union-member on FunctionTypeInfo::ExceptionSpecTokens,
triggering a segfault later on when the pointer is used.


Repository:
  rC Clang

https://reviews.llvm.org/D65913

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp


Index: clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
===
--- clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
+++ clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
@@ -9,6 +9,7 @@
 
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=array
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=array -DPR28423
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=array -DDEFAULT_ARG
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=pair
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=priority_queue
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions 
-fcxx-exceptions -DCLASS=stack
@@ -48,7 +49,11 @@
 #endif
 A member;
 #ifndef MSVC
+#ifndef DEFAULT_ARG
 void swap(CLASS &other) noexcept(noexcept(swap(member, other.member)));
+#else
+void swap(CLASS &other, int = 0) noexcept(noexcept(swap(member, 
other.member)));
+#endif
 #endif
   };
 
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2180,8 +2180,10 @@
 LateMethod->TemplateScope = getCurScope()->isTemplateParamScope();
 
 // Stash the exception-specification tokens in the late-pased method.
-LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens;
-FTI.ExceptionSpecTokens = nullptr;
+if (FTI.getExceptionSpecType() == EST_Unparsed) {
+  LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens;
+  FTI.ExceptionSpecTokens = nullptr;
+}
 
 // Push tokens for each parameter.  Those that do not have
 // defaults will be NULL.


Index: clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
===
--- clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
+++ clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
@@ -9,6 +9,7 @@
 
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array -DPR28423
+// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array -DDEFAULT_ARG
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=pair
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=priority_queue
 // RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=stack
@@ -48,7 +49,11 @@
 #endif
 A member;
 #ifndef MSVC
+#ifndef DEFAULT_ARG
 void swap(CLASS &other) noexcept(noexcept(swap(member, other.member)));
+#else
+void swap(CLASS &other, int = 0) noexcept(noexcept(swap(member, other.member)));
+#endif
 #endif
   };
 
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2180,8 +2180,10 @@
 LateMethod->TemplateScope = getCurScope()->isTemplateParamScope();
 
 // Stash the exception-specification tokens in the late-pased method.
-LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens;
-FTI.ExceptionSpecTokens = nullptr;
+if (FTI.getExceptionSpecType() == EST_Unparsed) {
+  LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens;
+  FTI.ExceptionSpecTokens = nullptr;
+}
 
 // Push tokens for each parameter.  Those that do not have
 // defaults will be NULL.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128406: clang: Tweak behaviour of warn_empty_while_body and warn_empty_if_body

2022-06-22 Thread Brad Moody via Phabricator via cfe-commits
bmoody created this revision.
bmoody added reviewers: rnk, gribozavr.
Herald added a project: All.
bmoody requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use the if/while statement right paren location instead of the end of the
condition expression to determine if the semicolon is on its own line, for the
purpose of not warning about code like this:

  while (foo())
;

Using the condition location meant that we would also not report a warning on
code like this:

  while (MACRO(a,
   b));
body();

The right paren loc wasn't stored in the AST or passed into Sema::ActOnIfStmt
when this logic was first written.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128406

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
  clang/test/SemaCXX/warn-empty-body.cpp


Index: clang/test/SemaCXX/warn-empty-body.cpp
===
--- clang/test/SemaCXX/warn-empty-body.cpp
+++ clang/test/SemaCXX/warn-empty-body.cpp
@@ -6,6 +6,8 @@
 
 #define MACRO_A 0
 
+#define AND(x, y) ((x) && (y))
+
 void test1(int x, int y) {
   while(true) {
 if (x); // expected-warning {{if statement has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
@@ -15,6 +17,15 @@
 if (x == MACRO_A); // expected-warning {{if statement has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
 if (MACRO_A == x); // expected-warning {{if statement has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
 
+// Check that we handle the case where the condition comes from a macro
+// expansion over multiple lines.
+if (AND(b(),
+c())); // expected-warning {{if statement has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
+
+while (AND(b(),
+   c())); // expected-warning{{while loop has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
+  a(0);
+
 int i;
 // PR11329
 for (i = 0; i < x; i++); { // expected-warning{{for loop has empty body}} 
expected-note{{put the semicolon on a separate line to silence this warning}}
Index: clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
@@ -63,8 +63,6 @@
   // expected-note@-1 {{to match this '('}}
   // expected-error@-2 {{expected ';' after expression}}
   // expected-error@-3 {{expected expression}}
-  // expected-warning@-4 {{while loop has empty body}}
-  // expected-note@-5 {{put the semicolon on a separate line to silence this 
warning}}
 }
 
 // TODO: This is needed because clang can't seem to diagnose invalid syntax 
after the
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -888,8 +888,7 @@
 CommaVisitor(*this).Visit(CondExpr);
 
   if (!ConstevalOrNegatedConsteval && !elseStmt)
-DiagnoseEmptyStmtBody(CondExpr->getEndLoc(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   if (ConstevalOrNegatedConsteval ||
   StatementKind == IfStatementKind::Constexpr) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -16673,7 +16673,7 @@
 Body = FS->getBody();
 DiagID = diag::warn_empty_for_body;
   } else if (const WhileStmt *WS = dyn_cast(S)) {
-StmtLoc = WS->getCond()->getSourceRange().getEnd();
+StmtLoc = WS->getRParenLoc();
 Body = WS->getBody();
 DiagID = diag::warn_empty_while_body;
   } else


Index: clang/test/SemaCXX/warn-empty-body.cpp
===
--- clang/test/SemaCXX/warn-empty-body.cpp
+++ clang/test/SemaCXX/warn-empty-body.cpp
@@ -6,6 +6,8 @@
 
 #define MACRO_A 0
 
+#define AND(x, y) ((x) && (y))
+
 void test1(int x, int y) {
   while(true) {
 if (x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
@@ -15,6 +17,15 @@
 if (x == MACRO_A); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
 if (MACRO_A == x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
 
+// Check that we handle the case where the condition comes from a macro
+// expansion over multiple lines.
+if (AND(b(),
+  

[PATCH] D128406: clang: Tweak behaviour of warn_empty_while_body and warn_empty_if_body

2022-06-23 Thread Brad Moody via Phabricator via cfe-commits
bmoody added a comment.

I don't have merge access so please merge on my behalf :) Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128406

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