|
5 | 5 |
|
6 | 6 | #include <clang/AST/RecordLayout.h> |
7 | 7 | #include <clang/Basic/OperatorKinds.h> |
| 8 | +#include <clang/Lex/Lexer.h> |
8 | 9 | #include <llvm/Support/ErrorHandling.h> |
9 | 10 |
|
10 | 11 | #include <algorithm> |
@@ -1238,15 +1239,17 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) { |
1238 | 1239 | expr->getArg(is_fprintf)->IgnoreImplicit())); |
1239 | 1240 | bool ends_newline = format.ends_with("\\n\""); |
1240 | 1241 |
|
1241 | | - const clang::NamedDecl *stream = nullptr; |
1242 | | - if (auto *ref = clang::dyn_cast<clang::DeclRefExpr>( |
1243 | | - expr->getArg(0)->IgnoreParenImpCasts())) { |
1244 | | - stream = ref->getDecl(); |
| 1242 | + llvm::StringRef stream = "stdout"; |
| 1243 | + if (is_fprintf) { |
| 1244 | + auto loc = expr->getArg(0)->IgnoreParenImpCasts()->getBeginLoc(); |
| 1245 | + stream = loc.isMacroID() |
| 1246 | + ? clang::Lexer::getImmediateMacroName( |
| 1247 | + loc, ctx_.getSourceManager(), ctx_.getLangOpts()) |
| 1248 | + : ""; |
1245 | 1249 | } |
1246 | | - if (!is_fprintf || IsCDecl(stream, "stdout") || |
1247 | | - IsCDecl(stream, "__stdoutp")) { |
| 1250 | + if (stream == "stdout") { |
1248 | 1251 | StrCat(ends_newline ? "println!(" : "print!("); |
1249 | | - } else if (IsCDecl(stream, "stderr") || IsCDecl(stream, "__stderrp")) { |
| 1252 | + } else if (stream == "stderr") { |
1250 | 1253 | StrCat(ends_newline ? "eprintln!(" : "eprint!("); |
1251 | 1254 | } else { |
1252 | 1255 | llvm::errs() << "Unknown fprintf fd:\n"; |
|
0 commit comments