[PATCH] D17348: Add -Wcast-calling-convention to warn when casting away calling conventions

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 23 15:52:21 PST 2016


rtrieu added inline comments.

================
Comment at: lib/Sema/SemaCast.cpp:1729
@@ +1728,3 @@
+/// defined in the current TU.
+static void diagnoseCallingConvCast(Sema &Self, const ExprResult &SrcExpr,
+                                    QualType DstType, SourceRange OpRange) {
----------------
Capitalize Diagnose like the other Diagnose functions in the file.

================
Comment at: lib/Sema/SemaCast.cpp:1752-1753
@@ +1751,4 @@
+  Expr *Src = SrcExpr.get()->IgnoreParenImpCasts();
+  if (auto *AddrOf = dyn_cast<UnaryOperator>(Src))
+    Src = AddrOf->getSubExpr()->IgnoreParenImpCasts();
+  auto *DRE = dyn_cast<DeclRefExpr>(Src);
----------------
Which UnaryOperator are you attempting to strip off here?  This one will strip off every UnaryOperator.

================
Comment at: lib/Sema/SemaCast.cpp:1769-1773
@@ +1768,7 @@
+  SourceLocation NameLoc = Definition->getNameInfo().getLoc();
+  SmallString<64> CCAttrText;
+  if (Self.getLangOpts().MicrosoftExt)
+    (Twine("__") + DstCCName + " ").toVector(CCAttrText);
+  else
+    (Twine("__attribute__((") + DstCCName + ")) ").toVector(CCAttrText);
+  Self.Diag(NameLoc, diag::note_change_calling_conv_fixit)
----------------
Usually in Sema, we uses a SmallVector backed ostream for making custom strings.
```
SmallString<64> CCAttrText;
llvm::raw_svector_ostream OS(CCAttrText);
OS << "some string";
```


http://reviews.llvm.org/D17348





More information about the cfe-commits mailing list