[PATCH] [CodeGen] Reuse stack space from unused function results (with more accurate unused result detection)
Leny Kholodov
leny.kholodov at gmail.com
Tue May 26 15:12:03 PDT 2015
Hi rnk,
This patch fixes issues with unused result detection which were found in patch http://reviews.llvm.org/D9743.
For detection of unused result the method CodeGenFunction::EmitCall uses similar approach to Sema::DiagnoseUnusedExprResult. Sema::DiagnoseUnusedExprResult uses underlying method Expr::isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) for accurate detection. This method has few drawbacks for using outside of Sema class:
* it checks warn_unused_result attribute which in general case is not set;
* it modifies several parameters which are not required for unused result checking.
In general case, we want to see smth similar to this method but without warn_unused_attribute checking and without modifiable parameters. The most expected solution in this case may be to provide Expr::isUnusedResult method which the method isUnusedResultAWarning method should use. However, this can't be easily done because in this case all context information for diagnostic should be detected repeatedly inside isUnusedResultAWarning method. Same for warn_unused_attribute. Another solution might be to duplicate logic of isUnusedResultAWarning inside inUnusedResult, but this duplication is too big (few hundred LOC). Moreover, all changes inside isUnusedResultAWarning should be duplicated inside isUnusedResult too. So this doesn't look acceptable.
This patch provides solution which uses isUnusedResultAWarning as an underlying method for isUnusedResult. It extends the list of parameters of isUnusedResultAWarning with extra parameter alwaysWarnIfUnused (default value is false). Based on the isUnusedResult method patch detects unused result during the code generation.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D10042
Files:
include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/CodeGen/CGCall.cpp
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCXX/stack-reuse.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10042.26539.patch
Type: text/x-patch
Size: 18313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150526/ac901ea5/attachment.bin>
More information about the cfe-commits
mailing list