Re: r345866 - Reapply Logging: make os_log buffer size an integer constant expression.
On Thu, 2018-11-01 at 18:40 +, Tim Northover via cfe-commits wrote: > On 1 Nov 2018, at 18:36, Jan Vesely wrote: > > this patch seems to cause a build failure: > > Ugh. Reverted as r345871. > > Do you know what linker and other options you’re using? The only > failure I’ve been able to reproduce locally is when I introduced a > circular dependency. I'm using standard fedora 29 setup (with distcc but that is not involved in linking). I use BUILD_SHARED_LIBS=ON which I think might trigger the issue. thanks, Jan > > Cheers. > > Tim. > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits signature.asc Description: This is a digitally signed message part ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r345866 - Reapply Logging: make os_log buffer size an integer constant expression.
On 1 Nov 2018, at 18:36, Jan Vesely wrote: > this patch seems to cause a build failure: Ugh. Reverted as r345871. Do you know what linker and other options you’re using? The only failure I’ve been able to reproduce locally is when I introduced a circular dependency. Cheers. Tim. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r345866 - Reapply Logging: make os_log buffer size an integer constant expression.
Hi, this patch seems to cause a build failure: /usr/bin/ld: CMakeFiles/clangAST.dir/OSLog.cpp.o: in function `(anonymous namespace)::OSLogFormatStringHandler::~OSLogFormatStringHandler()': /home/jvesely/llvm/tools/clang/lib/AST/OSLog.cpp:18: undefined reference to `clang::analyze_format_string::FormatStringHandler::~FormatStringHandler()' /usr/bin/ld: CMakeFiles/clangAST.dir/OSLog.cpp.o: in function `(anonymous namespace)::OSLogFormatStringHandler::~OSLogFormatStringHandler()': /home/jvesely/llvm/tools/clang/lib/AST/OSLog.cpp:18: undefined reference to `clang::analyze_format_string::FormatStringHandler::~FormatStringHandler()' /usr/bin/ld: CMakeFiles/clangAST.dir/OSLog.cpp.o: in function `clang::analyze_os_log::computeOSLogBufferLayout(clang::ASTContext&, clang::CallExpr const*, clang::analyze_os_log::OSLogBufferLayout&)': /home/jvesely/llvm/tools/clang/lib/AST/OSLog.cpp:198: undefined reference to `clang::analyze_format_string::ParsePrintfString(clang::analyze_format_string::FormatStringHandler&, char const*, char const*, clang::LangOptions const&, clang::TargetInfo const&, bool)' /usr/bin/ld: /home/jvesely/llvm/tools/clang/lib/AST/OSLog.cpp:18: undefined reference to `clang::analyze_format_string::FormatStringHandler::~FormatStringHandler()' collect2: error: ld returned 1 exit status thanks, Jan On Thu, Nov 1, 2018 at 2:06 PM Tim Northover via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: tnorthover > Date: Thu Nov 1 11:04:49 2018 > New Revision: 345866 > > URL: http://llvm.org/viewvc/llvm-project?rev=345866=rev > Log: > Reapply Logging: make os_log buffer size an integer constant expression. > > 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 helpers from libclangAnalysis to libclangAST > to avoid a circular dependency. > > Added: > cfe/trunk/include/clang/AST/OSLog.h > cfe/trunk/lib/AST/OSLog.cpp > Removed: > cfe/trunk/include/clang/Analysis/Analyses/OSLog.h > cfe/trunk/lib/Analysis/OSLog.cpp > Modified: > cfe/trunk/lib/AST/CMakeLists.txt > cfe/trunk/lib/AST/ExprConstant.cpp > cfe/trunk/lib/Analysis/CMakeLists.txt > cfe/trunk/lib/Analysis/PrintfFormatString.cpp > cfe/trunk/lib/CodeGen/CGBuiltin.cpp > cfe/trunk/test/CodeGen/builtins.c > > Added: cfe/trunk/include/clang/AST/OSLog.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=345866=auto > > == > --- cfe/trunk/include/clang/AST/OSLog.h (added) > +++ cfe/trunk/include/clang/AST/OSLog.h Thu Nov 1 11:04:49 2018 > @@ -0,0 +1,155 @@ > +//= OSLog.h - Analysis of calls to os_log builtins --*- C++ > -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > > +//===--===// > +// > +// This file defines APIs for determining the layout of the data buffer > for > +// os_log() and os_trace(). > +// > > +//===--===// > + > +#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H > +#define LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H > + > +#include "clang/AST/ASTContext.h" > +#include "clang/AST/Expr.h" > + > +namespace clang { > +namespace analyze_os_log { > + > +/// An OSLogBufferItem represents a single item in the data written by a > call > +/// to os_log() or os_trace(). > +class OSLogBufferItem { > +public: > + enum Kind { > +// The item is a scalar (int, float, raw pointer, etc.). No further > copying > +// is required. This is the only kind allowed by os_trace(). > +ScalarKind = 0, > + > +// The item is a count, which describes the length of the following > item to > +// be copied. A count may only be followed by an item of kind > StringKind, > +// WideStringKind, or PointerKind. > +CountKind, > + > +// The item is a pointer to a C string. If preceded by a count 'n', > +// os_log() will copy at most 'n' bytes from the pointer. > +StringKind, > + > +// The item is a pointer to a block of raw data. This item must be > preceded > +// by a count 'n'. os_log() will copy exactly 'n' bytes from the > pointer. > +PointerKind, > + > +// The item is a pointer to an Objective-C object. os_log() may > retain the > +// object for later processing. > +ObjCObjKind, > + > +// The item is a pointer to wide-char string. > +WideStringKind, > + > +// The item is corresponding to the '%m' format specifier, no value is > +// populated in the buffer and the runtime is loading the errno
r345866 - Reapply Logging: make os_log buffer size an integer constant expression.
Author: tnorthover Date: Thu Nov 1 11:04:49 2018 New Revision: 345866 URL: http://llvm.org/viewvc/llvm-project?rev=345866=rev Log: Reapply Logging: make os_log buffer size an integer constant expression. 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 helpers from libclangAnalysis to libclangAST to avoid a circular dependency. Added: cfe/trunk/include/clang/AST/OSLog.h cfe/trunk/lib/AST/OSLog.cpp Removed: cfe/trunk/include/clang/Analysis/Analyses/OSLog.h cfe/trunk/lib/Analysis/OSLog.cpp Modified: cfe/trunk/lib/AST/CMakeLists.txt cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/Analysis/CMakeLists.txt cfe/trunk/lib/Analysis/PrintfFormatString.cpp cfe/trunk/lib/CodeGen/CGBuiltin.cpp cfe/trunk/test/CodeGen/builtins.c Added: cfe/trunk/include/clang/AST/OSLog.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=345866=auto == --- cfe/trunk/include/clang/AST/OSLog.h (added) +++ cfe/trunk/include/clang/AST/OSLog.h Thu Nov 1 11:04:49 2018 @@ -0,0 +1,155 @@ +//= OSLog.h - Analysis of calls to os_log builtins --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// +// +// This file defines APIs for determining the layout of the data buffer for +// os_log() and os_trace(). +// +//===--===// + +#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H +#define LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H + +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" + +namespace clang { +namespace analyze_os_log { + +/// An OSLogBufferItem represents a single item in the data written by a call +/// to os_log() or os_trace(). +class OSLogBufferItem { +public: + enum Kind { +// The item is a scalar (int, float, raw pointer, etc.). No further copying +// is required. This is the only kind allowed by os_trace(). +ScalarKind = 0, + +// The item is a count, which describes the length of the following item to +// be copied. A count may only be followed by an item of kind StringKind, +// WideStringKind, or PointerKind. +CountKind, + +// The item is a pointer to a C string. If preceded by a count 'n', +// os_log() will copy at most 'n' bytes from the pointer. +StringKind, + +// The item is a pointer to a block of raw data. This item must be preceded +// by a count 'n'. os_log() will copy exactly 'n' bytes from the pointer. +PointerKind, + +// The item is a pointer to an Objective-C object. os_log() may retain the +// object for later processing. +ObjCObjKind, + +// The item is a pointer to wide-char string. +WideStringKind, + +// The item is corresponding to the '%m' format specifier, no value is +// populated in the buffer and the runtime is loading the errno value. +ErrnoKind + }; + + enum { +// The item is marked "private" in the format string. +IsPrivate = 0x1, + +// The item is marked "public" in the format string. +IsPublic = 0x2 + }; + +private: + Kind TheKind = ScalarKind; + const Expr *TheExpr = nullptr; + CharUnits ConstValue; + CharUnits Size; // size of the data, not including the header bytes + unsigned Flags = 0; + +public: + OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags) + : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {} + + OSLogBufferItem(ASTContext , CharUnits value, unsigned flags) + : TheKind(CountKind), ConstValue(value), +Size(Ctx.getTypeSizeInChars(Ctx.IntTy)), Flags(flags) {} + + unsigned char getDescriptorByte() const { +unsigned char result = 0; +if (getIsPrivate()) + result |= IsPrivate; +if (getIsPublic()) + result |= IsPublic; +result |= ((unsigned)getKind()) << 4; +return result; + } + + unsigned char getSizeByte() const { return size().getQuantity(); } + + Kind getKind() const { return TheKind; } + bool getIsPrivate() const { return (Flags & IsPrivate) != 0; } + bool getIsPublic() const { return (Flags & IsPublic) != 0; } + + const Expr *getExpr() const { return TheExpr; } + CharUnits getConstValue() const { return ConstValue; } + CharUnits size() const { return Size; } +}; + +class OSLogBufferLayout { +public: + SmallVector Items; + + enum Flags { HasPrivateItems = 1, HasNonScalarItems = 1 << 1 }; + + CharUnits size() const { +CharUnits result; +result += CharUnits::fromQuantity(2); // summary