changeset 65:35ab9e3560be

remove null pointer access bug which occured if the callee codesegment is accessed by pointer on LowerCallTo().
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 11 Feb 2014 02:09:46 +0900
parents 0aa33659e8e4
children 7a5097301ce3
files lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp tools/clang/lib/Parse/ParseCbC.cpp
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Mon Feb 03 18:02:13 2014 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Feb 11 02:09:46 2014 +0900
@@ -5460,8 +5460,14 @@
          "Null value expected with tail call!");
 #ifndef noCbC
   // if code segment's tail call flag was changed false , we report it on error.
-  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && !isTailCall)
-    DAG.getContext()->emitError(CS.getInstruction(),CS.getCalledFunction()->getName() + " : Tail call elimination was failed!");
+  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && !isTailCall) {
+    if (CS.getCalledFunction()) // if this call is direct access; ex)  goto codesegment();
+      DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + " : Tail call elimination was failed on goto "
+				  + CS.getCalledFunction()->getName() + " !");
+    else if (CS.getCalledValue()->getType()->isPointerTy()) // if the pointer access; ex) goto codesegmentPointer;
+      DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + 
+				  " : Tail call elimination was failed on codesegment which is accessed by pointer!"); // we can't get name from Type...
+  }
 #endif
   if (Result.first.getNode()) {
     setValue(CS.getInstruction(), Result.first);
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Mon Feb 03 18:02:13 2014 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Tue Feb 11 02:09:46 2014 +0900
@@ -337,7 +337,7 @@
   D.setFunctionDefinitionKind(FDK_Declaration);
   DeclarationNameInfo NameInfo = Actions.GetNameForDeclarator(D);
   DeclContext *DC = Actions.CurContext;
-  QualType R = Actions.getCurFunctionDecl()->getResultType(); // copy a  type
+  QualType R = Actions.getCurFunctionDecl()->getResultType(); // copy a type
   TypeSourceInfo *TInfo = Actions.Context.CreateTypeSourceInfo(R); // copy a type infomation
   Scope *S = getCurScope();
   LookupResult Previous(Actions, NameInfo, Actions.LookupOrdinaryName, Actions.ForRedeclaration);