[cfe-dev] [clang-tools-extra] r179103 - Fix UseNullptr fails to replace c-style explicit cast in a return statement
Vane, Edwin
edwin.vane at intel.com
Fri Jun 14 06:58:33 PDT 2013
These are compilation failures from simply compiling a lit test before the first transform is applied. This failure doesn't seem to have anything to do with the Migrator, and more to do with the nature of the test. You should get the same result just using clang++ -fsyntax-only. On Linux some of these errors are warnings caused by -Wnon-literal-null-conversion. I've never seen this test fail on windows and it hasn't changed in some time. Looking back through the build history of this builder this test was passing as of http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/2055. My guess something changed in clang in how it handles this kind of code.
Does clang treat warnings/errors differently on windows than on Linux? Did something change recently in clang that might cause these errors to pop up on windows. I don't see them in Linux with a clean build of llvm/clang/Migrator.
> -----Original Message-----
> From: Bernal, Ariel J
> Sent: Friday, June 14, 2013 1:26 AM
> To: Rafael EspĂndola
> Cc: Vane, Edwin
> Subject: RE: [clang-tools-extra] r179103 - Fix UseNullptr fails to replace c-style
> explicit cast in a return statement
>
> From the log it seems that the test is failing during the first syntax check before
> any transform is applied. I don't see anything wrong with the test.
> I'll try to debug the test as soon as I get a windows built.
>
> -----Original Message-----
> From: Rafael EspĂndola [mailto:rafael.espindola at gmail.com]
> Sent: Thursday, June 13, 2013 11:24 PM
> To: Bernal, Ariel J
> Cc: llvm cfe
> Subject: Re: [clang-tools-extra] r179103 - Fix UseNullptr fails to replace c-style
> explicit cast in a return statement
>
> Any idea why this test is failing on windows? For example:
>
> http://bb.pgr.jp/builders/ninja-clang-i686-msc17-
> R/builds/2075/steps/test_clang_tools/logs/Clang%20Tools%20%3A%3A%20cpp
> 11-migrate__UseNullptr__basic.cpp
>
> On 9 April 2013 12:54, Ariel J. Bernal <ariel.j.bernal at intel.com> wrote:
> > Author: ajbernal
> > Date: Tue Apr 9 11:54:56 2013
> > New Revision: 179103
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=179103&view=rev
> > Log:
> > Fix UseNullptr fails to replace c-style explicit cast in a return
> > statement
> >
> > This happens whenever there is a c-style explicit cast to nullptr not
> > surrounded by parentheses following a return statement.
> >
> > - Added a white space before nullptr if the character before is alphanumeric
> > when replacing the null pointer expression.
> > - Simplified visitor
> > - Addes tests
> >
> > Modified:
> > clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
> > clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp
> >
> > Modified:
> > clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migr
> >
> ate/UseNullptr/NullptrActions.cpp?rev=179103&r1=179102&r2=179103&view=
> > diff
> >
> =================================================================
> =====
> > ========
> > ---
> > clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
> > (original)
> > +++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cp
> > +++ p Tue Apr 9 11:54:56 2013
> > @@ -20,6 +20,7 @@
> > #include "clang/AST/ASTContext.h"
> > #include "clang/AST/RecursiveASTVisitor.h"
> >
> > +#include "clang/Basic/CharInfo.h"
> > #include "clang/Lex/Lexer.h"
> >
> > using namespace clang::ast_matchers;
> > @@ -42,7 +43,14 @@ bool ReplaceWithNullptr(tooling::Replace
> > SourceLocation StartLoc, SourceLocation EndLoc) {
> > if (SM.isFromSameFile(StartLoc, EndLoc) && SM.isFromMainFile(StartLoc)) {
> > CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
> > - Replace.insert(tooling::Replacement(SM, Range, "nullptr"));
> > + // Add a space if nullptr follows an alphanumeric character. This happens
> > + // whenever there is an c-style explicit cast to nullptr not surrounded by
> > + // parentheses and right beside a return statement.
> > + SourceLocation PreviousLocation = StartLoc.getLocWithOffset(-1);
> > + if (isAlphanumeric(*FullSourceLoc(PreviousLocation,
> SM).getCharacterData()))
> > + Replace.insert(tooling::Replacement(SM, Range, " nullptr"));
> > + else
> > + Replace.insert(tooling::Replacement(SM, Range, "nullptr"));
> > return true;
> > } else
> > return false;
> > @@ -93,19 +101,11 @@ public:
> > // within a cast expression.
> > bool VisitStmt(Stmt *S) {
> > CastExpr *C = dyn_cast<CastExpr>(S);
> > -
> > if (!C) {
> > ResetFirstSubExpr();
> > return true;
> > } else if (!FirstSubExpr) {
> > - // Keep parentheses for implicit casts to avoid cases where an implicit
> > - // cast within a parentheses expression is right next to a return
> > - // statement otherwise get the subexpression of the outermost explicit
> > - // cast.
> > - if (C->getStmtClass() == Stmt::ImplicitCastExprClass)
> > - FirstSubExpr = C->IgnoreParenImpCasts();
> > - else
> > - FirstSubExpr = C->getSubExpr();
> > + FirstSubExpr = C->getSubExpr()->IgnoreParens();
> > }
> >
> > if (C->getCastKind() == CK_NullToPointer ||
> >
> > Modified:
> > clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11
> > -
> migrate/UseNullptr/basic.cpp?rev=179103&r1=179102&r2=179103&view=diff
> >
> =================================================================
> =====
> > ========
> > --- clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp
> > (original)
> > +++ clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp
> > +++ Tue Apr 9 11:54:56 2013
> > @@ -180,6 +180,18 @@ int test_function_return6() {
> > // CHECK: return g_null;
> > }
> >
> > +int *test_function_return_cast1() {
> > + return(int)0;
> > + // CHECK: return nullptr;
> > +}
> > +
> > +int *test_function_return_cast2() {
> > + #define RET return
> > + RET(int)0;
> > + // CHECK: RET nullptr;
> > + #undef RET
> > +}
> > +
> > // Test parentheses expressions resulting in a nullptr.
> > int *test_parentheses_expression1() {
> > return(0);
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-dev
mailing list