]> granicus.if.org Git - clang/commitdiff
Reapply Logging: make os_log buffer size an integer constant expression.
authorTim Northover <tnorthover@apple.com>
Fri, 2 Nov 2018 13:14:11 +0000 (13:14 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 2 Nov 2018 13:14:11 +0000 (13:14 +0000)
The size of an os_log buffer is known at any stage of compilation, so making it
a constant expression means that the common idiom of declaring a buffer for it
won't result in a VLA. That allows the compiler to skip saving and restoring
the stack pointer around such buffers.

This also moves the OSLog and other FormatString helpers from
libclangAnalysis to libclangAST to avoid a circular dependency.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345971 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/clang/AST/FormatString.h [moved from include/clang/Analysis/Analyses/FormatString.h with 100% similarity]
include/clang/AST/OSLog.h [moved from include/clang/Analysis/Analyses/OSLog.h with 100% similarity]
lib/AST/CMakeLists.txt
lib/AST/ExprConstant.cpp
lib/AST/FormatString.cpp [moved from lib/Analysis/FormatString.cpp with 100% similarity]
lib/AST/FormatStringParsing.h [moved from lib/Analysis/FormatStringParsing.h with 98% similarity]
lib/AST/OSLog.cpp [moved from lib/Analysis/OSLog.cpp with 98% similarity]
lib/AST/PrintfFormatString.cpp [moved from lib/Analysis/PrintfFormatString.cpp with 99% similarity]
lib/AST/ScanfFormatString.cpp [moved from lib/Analysis/ScanfFormatString.cpp with 99% similarity]
lib/Analysis/CMakeLists.txt
lib/CodeGen/CGBuiltin.cpp
lib/Sema/SemaChecking.cpp
test/CodeGen/builtins.c

index 4f868a3af59e4c2c86ac4d20bfa6436f5ddbf017..45ed87d670f4db1410a4e80a79a12f3c1d93230c 100644 (file)
@@ -39,6 +39,7 @@ add_clang_library(clangAST
   ExprObjC.cpp
   ExternalASTMerger.cpp
   ExternalASTSource.cpp
+  FormatString.cpp
   InheritViz.cpp
   ItaniumCXXABI.cpp
   ItaniumMangle.cpp
@@ -48,12 +49,15 @@ add_clang_library(clangAST
   NestedNameSpecifier.cpp
   NSAPI.cpp
   ODRHash.cpp
+  OSLog.cpp
   OpenMPClause.cpp
   ParentMap.cpp
+  PrintfFormatString.cpp
   QualTypeNames.cpp
   RawCommentList.cpp
   RecordLayout.cpp
   RecordLayoutBuilder.cpp
+  ScanfFormatString.cpp
   SelectorLocationsKind.cpp
   Stmt.cpp
   StmtCXX.cpp
index 15efe433bd1e055598f846207248526e4ee78298..a85d5cf9d5f389d8054f01697738bcd17ebd222f 100644 (file)
@@ -39,6 +39,7 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/OSLog.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/TypeLoc.h"
@@ -8126,6 +8127,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     llvm_unreachable("unexpected EvalMode");
   }
 
+  case Builtin::BI__builtin_os_log_format_buffer_size: {
+    analyze_os_log::OSLogBufferLayout Layout;
+    analyze_os_log::computeOSLogBufferLayout(Info.Ctx, E, Layout);
+    return Success(Layout.size().getQuantity(), E);
+  }
+
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
similarity index 98%
rename from lib/Analysis/FormatStringParsing.h
rename to lib/AST/FormatStringParsing.h
index a63140b366cd1217dd257739d8a82d7075f7e409..91fab155e4c4d9c9cdffcf3c0d28d15a1446ab86 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Type.h"
-#include "clang/Analysis/Analyses/FormatString.h"
+#include "clang/AST/FormatString.h"
 
 namespace clang {
 
similarity index 98%
rename from lib/Analysis/OSLog.cpp
rename to lib/AST/OSLog.cpp
index b2983932ea22747dedf86804f9c3d3d5800be5d2..cf20706c4b3ac9e0a0eaef3ec47c7976251a819a 100644 (file)
@@ -1,11 +1,11 @@
 // TODO: header template
 
-#include "clang/Analysis/Analyses/OSLog.h"
+#include "clang/AST/OSLog.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprObjC.h"
-#include "clang/Analysis/Analyses/FormatString.h"
+#include "clang/AST/FormatString.h"
 #include "clang/Basic/Builtins.h"
 #include "llvm/ADT/SmallBitVector.h"
 
similarity index 99%
rename from lib/Analysis/PrintfFormatString.cpp
rename to lib/AST/PrintfFormatString.cpp
index dcb15c5e3758435e69698270811c4d3808428cbe..96a8f258ed36202d50986a3c7853e44edde34010 100644 (file)
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/Analyses/FormatString.h"
-#include "clang/Analysis/Analyses/OSLog.h"
+#include "clang/AST/FormatString.h"
+#include "clang/AST/OSLog.h"
 #include "FormatStringParsing.h"
 #include "clang/Basic/TargetInfo.h"
 
similarity index 99%
rename from lib/Analysis/ScanfFormatString.cpp
rename to lib/AST/ScanfFormatString.cpp
index a9af0cdfdacd9006e382fac501f71f55e51ef30a..bda97c57c87c06edc8e40db00c2d016075b942c2 100644 (file)
@@ -12,7 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/Analyses/FormatString.h"
+#include "clang/AST/FormatString.h"
 #include "FormatStringParsing.h"
 #include "clang/Basic/TargetInfo.h"
 
index 36a37f498580733bc744fea2b7719da0fbdf1134..5345a56f2002e475e988c5b03b497b330ce97428 100644 (file)
@@ -16,15 +16,11 @@ add_clang_library(clangAnalysis
   CodeInjector.cpp
   Dominators.cpp
   ExprMutationAnalyzer.cpp
-  FormatString.cpp
   LiveVariables.cpp
-  OSLog.cpp
   ObjCNoReturn.cpp
   PostOrderCFGView.cpp
-  PrintfFormatString.cpp
   ProgramPoint.cpp
   ReachableCode.cpp
-  ScanfFormatString.cpp
   ThreadSafety.cpp
   ThreadSafetyCommon.cpp
   ThreadSafetyLogical.cpp
index 2c7a3d720a7eb84a614159da825813e9701947a4..f880e93068a9358b62c68203a2eac2702d4a3544 100644 (file)
@@ -21,7 +21,7 @@
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
-#include "clang/Analysis/Analyses/OSLog.h"
+#include "clang/AST/OSLog.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
@@ -3606,13 +3606,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
   case Builtin::BI__builtin_os_log_format:
     return emitBuiltinOSLogFormat(*E);
 
-  case Builtin::BI__builtin_os_log_format_buffer_size: {
-    analyze_os_log::OSLogBufferLayout Layout;
-    analyze_os_log::computeOSLogBufferLayout(CGM.getContext(), E, Layout);
-    return RValue::get(ConstantInt::get(ConvertType(E->getType()),
-                                        Layout.size().getQuantity()));
-  }
-
   case Builtin::BI__xray_customevent: {
     if (!ShouldXRayInstrumentFunction())
       return RValue::getIgnored();
index 792171a4f5d2a986b82e83086699346a834856bc..4660ed55aeea9edd24d8bcb38e45837c285f948e 100644 (file)
@@ -27,6 +27,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
+#include "clang/AST/FormatString.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/NonTrivialTypeVisitor.h"
 #include "clang/AST/OperationKinds.h"
@@ -35,7 +36,6 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/UnresolvedSet.h"
-#include "clang/Analysis/Analyses/FormatString.h"
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Diagnostic.h"
index 77b479e4c112b968d2254b250a547a57de978a6d..6ca3c414cf31d582b21aec1a2f80b4fa2bb8684b 100644 (file)
@@ -729,25 +729,28 @@ void test_builtin_os_log_merge_helper1(void *buf, unsigned u, long long ll) {
 
 // CHECK-LABEL: define void @test_builtin_os_log_errno
 void test_builtin_os_log_errno() {
-  // CHECK: %[[VLA:.*]] = alloca i8, i64 4, align 16
-  // CHECK: call void @__os_log_helper_16_2_1_0_96(i8* %[[VLA]])
+  // CHECK-NOT: @stacksave
+  // CHECK: %[[BUF:.*]] = alloca [4 x i8], align 1
+  // CHECK: %[[DECAY:.*]] = getelementptr inbounds [4 x i8], [4 x i8]* %[[BUF]], i32 0, i32 0
+  // CHECK: call void @__os_log_helper_1_2_1_0_96(i8* %[[DECAY]])
+  // CHECK-NOT: @stackrestore
 
   char buf[__builtin_os_log_format_buffer_size("%m")];
   __builtin_os_log_format(buf, "%m");
 }
 
-// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_16_2_1_0_96
+// CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_1_2_1_0_96
 // CHECK: (i8* %[[BUFFER:.*]])
 
 // CHECK: %[[BUFFER_ADDR:.*]] = alloca i8*, align 8
 // CHECK: store i8* %[[BUFFER]], i8** %[[BUFFER_ADDR]], align 8
 // CHECK: %[[BUF:.*]] = load i8*, i8** %[[BUFFER_ADDR]], align 8
 // CHECK: %[[SUMMARY:.*]] = getelementptr i8, i8* %[[BUF]], i64 0
-// CHECK: store i8 2, i8* %[[SUMMARY]], align 16
+// CHECK: store i8 2, i8* %[[SUMMARY]], align 1
 // CHECK: %[[NUMARGS:.*]] = getelementptr i8, i8* %[[BUF]], i64 1
 // CHECK: store i8 1, i8* %[[NUMARGS]], align 1
 // CHECK: %[[ARGDESCRIPTOR:.*]] = getelementptr i8, i8* %[[BUF]], i64 2
-// CHECK: store i8 96, i8* %[[ARGDESCRIPTOR]], align 2
+// CHECK: store i8 96, i8* %[[ARGDESCRIPTOR]], align 1
 // CHECK: %[[ARGSIZE:.*]] = getelementptr i8, i8* %[[BUF]], i64 3
 // CHECK: store i8 0, i8* %[[ARGSIZE]], align 1
 // CHECK-NEXT: ret void