Release 3.8 the Clang Team

Total Page:16

File Type:pdf, Size:1020Kb

Release 3.8 the Clang Team Clang Documentation Release 3.8 The Clang Team Aug 19, 2017 Contents 1 Introduction 3 2 What’s New in Clang 3.8? 5 3 Additional Information 13 4 Using Clang as a Compiler 15 5 Using Clang as a Library 257 6 Using Clang Tools 283 7 Design Documents 299 8 Indices and tables 347 i ii Clang Documentation, Release 3.8 • Introduction • What’s New in Clang 3.8? – Improvements to Clang’s diagnostics – New Compiler Flags – Alignment – C Language Changes in Clang – OpenCL C Language Changes in Clang – OpenMP Support in Clang – CUDA Support in Clang – Internal API Changes – AST Matchers – Static Analyzer – Clang-tidy • Additional Information Written by the LLVM Team Contents 1 Clang Documentation, Release 3.8 2 Contents CHAPTER 1 Introduction This document contains the release notes for the Clang C/C++/Objective-C frontend, part of the LLVM Compiler Infrastructure, release 3.8. Here we describe the status of Clang in some detail, including major improvements from the previous release and new feature work. For the general LLVM release notes, see the LLVM documentation. All LLVM releases may be downloaded from the LLVM releases web site. For more information about Clang or LLVM, including information about the latest release, please check out the main please see the Clang Web Site or the LLVM Web Site. 3 Clang Documentation, Release 3.8 4 Chapter 1. Introduction CHAPTER 2 What’s New in Clang 3.8? Some of the major new features and improvements to Clang are listed here. Generic improvements to Clang as a whole or to its underlying infrastructure are described first, followed by language-specific sections with improvements to Clang’s support for those languages. Improvements to Clang’s diagnostics Clang’s diagnostics are constantly being improved to catch more issues, explain them more clearly, and provide more accurate source information about them. The improvements since the 3.7 release include: • -Wmicrosoft has been split into many targeted flags, so that projects can choose to enable only a subset of these warnings. -Wno-microsoft still disables all these warnings, and -Wmicrosoft still enables them all. New Compiler Flags Clang can “tune” DWARF debugging information to suit one of several different debuggers. This fine-tuning can mean omitting DWARF features that the debugger does not need or use, or including DWARF extensions specific to the debugger. Clang supports tuning for three debuggers, as follows. • -ggdb is equivalent to -g plus tuning for the GDB debugger. For compatibility with GCC, Clang allows this option to be followed by a single digit from 0 to 3 indicating the debugging information “level.” For example, -ggdb1 is equivalent to -ggdb -g1. • -glldb is equivalent to -g plus tuning for the LLDB debugger. • -gsce is equivalent to -g plus tuning for the Sony Computer Entertainment debugger. Specifying -g without a tuning option will use a target-dependent default. The new -fstrict-vtable-pointers flag enables better devirtualization support (experimental). 5 Clang Documentation, Release 3.8 Alignment Clang has gotten better at passing down strict type alignment information to LLVM, and several targets have gotten better at taking advantage of that information. Dereferencing a pointer that is not adequately aligned for its type is undefined behavior. It may crash on target architectures that strictly enforce alignment, but even on architectures that do not, frequent use of unaligned pointers may hurt the performance of the generated code. If you find yourself fixing a bug involving an inadequately aligned pointer, you have several options. The best option, when practical, is to increase the alignment of the memory. For example, this array is not guaranteed to be sufficiently aligned to store a pointer value: char buffer[sizeof(const char*)]; Writing a pointer directly into it violates C’s alignment rules: ((const char**) buffer)[0]="Hello, world! \n"; But you can use alignment attributes to increase the required alignment: __attribute__((aligned(__alignof__(const char*)))) char buffer[sizeof(const char*)]; When that’s not practical, you can instead reduce the alignment requirements of the pointer. If the pointer is to a struct that represents that layout of a serialized structure, consider making that struct packed; this will remove any implicit internal padding that the compiler might add to the struct and reduce its alignment requirement to 1. struct file_header { uint16_t magic_number; uint16_t format_version; uint16_t num_entries; } __attribute__((packed)); You may also override the default alignment assumptions of a pointer by using a typedef with explicit alignment: typedef const char *unaligned_char_ptr __attribute__((aligned(1))); ((unaligned_char_ptr*) buffer)[0]="Hello, world! \n"; The final option is to copy the memory into something that is properly aligned. Be aware, however, that Clang will assume that pointers are properly aligned for their type when you pass them to a library function like memcpy. For example, this code will assume that the source and destination pointers are both properly aligned for an int: void copy_int_array(int *dest, const int *src, size_t num) { memcpy(dest, src, num * sizeof(int)); } You may explicitly disable this assumption by casting the argument to a less-aligned pointer type: void copy_unaligned_int_array(int *dest, const int *src, size_t num) { memcpy((char*) dest, (const char*) src, num * sizeof(int)); } Clang promises not to look through the explicit cast when inferring the alignment of this memcpy. 6 Chapter 2. What’s New in Clang 3.8? Clang Documentation, Release 3.8 C Language Changes in Clang Better support for __builtin_object_size Clang 3.8 has expanded support for the __builtin_object_size intrinsic. Specifically, __builtin_object_size will now fail less often when you’re trying to get the size of a subobject. Additionally, the pass_object_size attribute was added, which allows __builtin_object_size to successfully report the size of function parameters, without requiring that the function be inlined. overloadable attribute relaxations Previously, functions marked overloadable in C would strictly use C++’s type conversion rules, so the following code would not compile: void foo(char *bar, char *baz) __attribute__((overloadable)); void foo(char *bar) __attribute__((overloadable)); void callFoo() { int a; foo(&a); } Now, Clang is able to selectively use C’s type conversion rules during overload resolution in C, which allows the above example to compile (albeit potentially with a warning about an implicit conversion from int* to char*). OpenCL C Language Changes in Clang Several OpenCL 2.0 features have been added, including: • Command-line option -std=CL2.0. • Generic address space (__generic) along with new conversion rules between different address spaces and default address space deduction. • Support for program scope variables with __global address space. • Pipe specifier was added (although no pipe functions are supported yet). • Atomic types: atomic_int, atomic_uint, atomic_long, atomic_ulong, atomic_float, atomic_double, atomic_flag, atomic_intptr_t, atomic_uintptr_t, atomic_size_t, atomic_ptrdiff_t and their usage with C11 style builtin functions. • Image types: image2d_depth_t, image2d_array_depth_t, image2d_msaa_t, image2d_array_msaa_t, image2d_msaa_depth_t, image2d_array_msaa_depth_t. • Other types (for pipes and device side enqueue): clk_event_t, queue_t, ndrange_t, reserve_id_t. Several additional features/bugfixes have been added to the previous standards: • A set of floating point arithmetic relaxation flags: -cl-no-signed-zeros, -cl-unsafe-math-optimizations, -cl-finite-math-only, -cl-fast-relaxed-math. • Added ^^ to the list of reserved operations. • Improved vector support and diagnostics. • Improved diagnostics for function pointers. 2.4. C Language Changes in Clang 7 Clang Documentation, Release 3.8 OpenMP Support in Clang OpenMP 3.1 is fully supported and is enabled by default with -fopenmp which now uses the Clang OpenMP library instead of the GCC OpenMP library. The runtime can be built in-tree. In addition to OpenMP 3.1, several important elements of the OpenMP 4.0/4.5 are supported as well. We continue to aim to complete OpenMP 4.5 • map clause • task dependencies • num_teams clause • thread_limit clause • target and target data directive • target directive with implicit data mapping • target enter data and target exit data directive • Array sections [2.4, Array Sections]. • Directive name modifiers for if clause [2.12, if Clause]. • linear clause can be used in loop-based directives [2.7.2, loop Construct]. • simdlen clause [2.8, SIMD Construct]. • hint clause [2.13.2, critical Construct]. • Parsing/semantic analysis of all non-device directives introduced in OpenMP 4.5. The codegen for OpenMP constructs was significantly improved allowing us to produce much more stable and fast code. Full test cases of IR are also implemented. CUDA Support in Clang Clang has experimental support for end-to-end CUDA compilation now: • The driver now detects CUDA installation, creates host and device compilation pipelines, links device-side code with appropriate CUDA bitcode and produces single object file with host and GPU code. • Implemented target attribute-based function overloading which allows Clang to compile CUDA sources without splitting them into separate host/device TUs. Internal API Changes These are major API changes that have happened since the 3.7 release of Clang. If upgrading an external codebase that uses Clang as a library, this section should help get you
Recommended publications
  • Object Pascal Language Guide
    Object Pascal Language Guide Borland® Object Pascal Borland Software Corporation 100 Enterprise Way, Scotts Valley, CA 95066-3249 www.borland.com Borland Software Corporation may have patents and/or pending patent applications covering subject matter in this document. The furnishing of this document does not give you any license to these patents. COPYRIGHT © 1983, 2002 Borland Software Corporation. All rights reserved. All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation. Other brand and product names are trademarks or registered trademarks of their respective holders. Printed in the U.S.A. ALP0000WW21000 1E0R0102 0203040506-9 8 7654321 D3 Contents Chapter 1 Qualified identifiers . 4-2 Introduction 1-1 Reserved words . 4-3 Directives. 4-3 What’s in this manual? . 1-1 Numerals. 4-4 Using Object Pascal . 1-1 Labels . 4-4 Typographical conventions . 1-2 Character strings . 4-4 Other sources of information . 1-2 Comments and compiler directives. 4-5 Software registration and technical support . 1-3 Expressions . 4-5 Part I Operators. 4-6 Arithmetic operators . 4-6 Basic language description Boolean operators . 4-7 Logical (bitwise) operators . 4-8 Chapter 2 String operators . 4-9 Overview 2-1 Pointer operators. 4-9 Program organization . 2-1 Set operators . 4-10 Pascal source files . 2-1 Relational operators . 4-11 Other files used to build applications . 2-2 Class operators. 4-12 Compiler-generated files . 2-3 The @ operator . 4-12 Example programs. 2-3 Operator precedence rules . 4-12 A simple console application . 2-3 Function calls . 4-13 A more complicated example .
    [Show full text]
  • Syntactic Sugar and Obfuscated Code: Why Learning C Is Challenging for Novice Programmers
    TECHNICAL REPORT Syntactic sugar and obfuscated code: Why learning C is challenging for novice programmers Michael Wirth School of Computer Science University of Guelph Sally sold C shells by the C shore. But should she have? C is an inherently complex language, not from the perspective of the language, because it is a small language in comparison to the likes of Ada or C++. However there is an inherent complexity to learning the language because of its assembly-like heritage. This white-paper overviews some of the more challenging aspects of C from the perspective of the novice programmer, and offers alternatives from other languages, where the usability may be improved. 1. Introduction 2. C - Language Synopsis 3. Datatypes 4. Symbolic confusion 5. Permissiveness 6. Incoherent control structures 7. Lack of consistency 8. Arrays 9. Pointers and memory 10. Functions and parameter passing 11. Failure to build on existing knowledge 12. Code brevity and condensation 13. Input snaffus 14. Hoodwinking the compiler 15. C code is just plain crazy 16. Conclusion June 2018 TECHNICAL REPORT 1. Introduction The debate over the choice of programming language use in CS1 (the core introductory programming course) has been going on as long as languages have been used to teach programming. Fundamentally CS1 has three basic goals. The first involves disseminating the basic principles of programming, such as decision statements, repetition, modularity, testing, readability etc. The second involves teaching how the basic principles are implemented in a specific programming language. The third involves showing how programming can be used to solve problems. It is the latter which spurs interest in programming - taking a problem, and deriving a solution which can then be turned into a program.
    [Show full text]
  • IDL-What You Need to Know
    Bolinger IDL 5.3 Notes IDL 5.3 Things you need to know Manuals The manuals are available as PDF files. They should be loaded on the computers, if not, we need to ask for them to be installed. They are in PDF format and require Acrobat reader 3.0 or higher. To get to the online manuals: On Windows, select Start -> Programs -> Research Systems IDL 5.3 -> IDL Online Manuals On Macintosh, a shortcut can be found in the rsi-directory:RSI:IDL 5.3 folder named IDL Online Manuals. On UNIX, execute the following at the UNIX prompt: idlman This is the best set of online manuals I have seen for any program. They are exact copies of the hard copy manuals and have been carefully developed over 15 years. Getting Started with IDL – Everyone new to IDL should look though this manual. It quickly covers many important features and points you to the manuals that have more details about the topics. It is about 200 pages long with lots of pictures and examples for you to try. So it should be used when you are at a computer so that you can try everything out. This manual covers the IDL Development Environment, Reading and Writing data, plotting, signal processing, image processing, surface and contour plotting, volume visualization, mapping (which few of you will use), plotting irregularly-gridded data, animation, programming in IDL, manipulating data and using the IDL GUIBuilder. It even has a chapter that is a road map of the rest of the documentation set and manuals.
    [Show full text]
  • Perl Programmers Reference Guide PERL(1)
    PERL(1) Perl Programmers Reference Guide PERL(1) NAME perl − The Perl 5 language interpreter SYNOPSIS perl [ −sTtuUWX ][−hv ][−V[:configvar]] [ −cw ][−d[t][:debugger]][−D[number/list]] [ −pna ][−Fpattern ][−l[octal]][−0[octal/hexadecimal]] [ −Idir ][−m[−]module ][−M[−]’module...’ ][−f ][−C [number/list] ][−S ] [ −x[dir]] [−i[extension]] [[−e|−E] ’command’ ][−− ][programfile ][argument ]... Formore information on these options, you can run perldoc perlrun. GETTING HELP The perldoc program givesyou access to all the documentation that comes with Perl. Youcan get more documentation, tutorials and community support online at <http://www.perl.org/>. If you’re newtoPerl, you should start by running perldoc perlintro,which is a general intro for beginners and provides some background to help you navigate the rest of Perl’sextensive documentation. Run perldoc perldoc to learn more things you can do with perldoc. Forease of access, the Perl manual has been split up into several sections. Overview perl Perl overview (this section) perlintro Perl introduction for beginners perlrun Perl execution and options perltoc Perl documentation table of contents Tutorials perlreftut Perl references short introduction perldsc Perl data structures intro perllol Perl data structures: arrays of arrays perlrequick Perl regular expressions quick start perlretut Perl regular expressions tutorial perlootut Perl OO tutorial for beginners perlperf Perl Performance and Optimization Techniques perlstyle Perl style guide perlcheat Perl cheat sheet perltrap Perl traps for
    [Show full text]
  • Computer Arithmetic
    APPENDIX A Computer Arithmetic In the chapters of this book, I've deliberately kept discussion of arithmetic to a minimum. However, it's important, so I'm going to quickly go over the subject in this appendix. If you feel confident in your math skills, this review will be old hat to you. If you find the math parts tough, this section should show you how easy it really is. Binary Numbers First, let's consider exactly what you intend when you write a common, everyday decimal number such as 324 or 911. Obviously what you mean is three hundred and twenty-four oi nine hundred and eleven. Put more precisely, you mean the following: 324 is 3 X 102 + 2 X IQl + 4 X 10^, which is 3 x 10 x 10 + 2 x 10 + 4 911 is 9 X 102 + 1 X 10^ + 1 X 10^, which is 9 x 10 x 10 + 1 x 10 + 1 We call this decimal notation because it's built around powers of 10. (This is derived from the Latin decimalis, meaning "of tithes," which was a tax of 10 percent. Ah, those were the days ...) Representing numbers in this way is very handy for people with 10 fingers and/or 10 toes, or indeed 10 of any kind of appendage. However, your PC is rather less handy, being built mainly of switches that are either on or off. It's OK for counting up to 2, but not spectacular at counting to 10. I'm sure you're aware that this is the primary reason why your computer represents numbers using base 2 rather than base 10.
    [Show full text]
  • Building IDL Applications
    Building IDL Applications IDL Version 6.1 July, 2004 Edition Copyright © Research Systems, Inc. All Rights Reserved 0704IDL61BLD Restricted Rights Notice The IDL®, ION Script™, and ION Java™ software programs and the accompanying procedures, functions, and documentation described herein are sold under license agreement. Their use, duplication, and disclosure are subject to the restrictions stated in the license agreement. Research Systems, Inc., reserves the right to make changes to this document at any time and without notice. Limitation of Warranty Research Systems, Inc. makes no warranties, either express or implied, as to any matter not expressly set forth in the license agreement, including without limitation the condition of the software, merchantability, or fitness for any particular purpose. Research Systems, Inc. shall not be liable for any direct, consequential, or other damages suffered by the Lic- ensee or any others resulting from use of the IDL or ION software packages or their documentation. Permission to Reproduce this Manual If you are a licensed user of this product, Research Systems, Inc. grants you a limited, nontransferable license to reproduce this particular document provided such copies are for your use only and are not sold or distrib- uted to third parties. All such copies must contain the title page and this notice page in their entirety. Acknowledgments IDL® is a registered trademark and ION™, ION Script™, ION Java™, are trademarks of Research Systems Inc., registered in the United States Patent and Trademark Office, for the computer program described herein. Numerical Recipes™ is a trademark of Numerical Recipes Software. Numerical Recipes routines are used by permission.
    [Show full text]
  • Release 3.9 the Clang Team
    Clang Documentation Release 3.9 The Clang Team Aug 19, 2017 Contents 1 Introduction 3 2 What’s New in Clang 3.9? 5 3 Additional Information 9 4 Using Clang as a Compiler 11 5 Using Clang as a Library 275 6 Using Clang Tools 303 7 Design Documents 321 8 Indices and tables 371 i ii Clang Documentation, Release 3.9 • Introduction • What’s New in Clang 3.9? – Major New Features – Attribute Changes in Clang – Windows Support – C Language Changes in Clang – C++ Language Changes in Clang – OpenCL C Language Changes in Clang – OpenMP Support in Clang – AST Matchers – Static Analyzer • Additional Information Written by the LLVM Team Contents 1 Clang Documentation, Release 3.9 2 Contents CHAPTER 1 Introduction This document contains the release notes for the Clang C/C++/Objective-C frontend, part of the LLVM Compiler Infrastructure, release 3.9. Here we describe the status of Clang in some detail, including major improvements from the previous release and new feature work. For the general LLVM release notes, see the LLVM documentation. All LLVM releases may be downloaded from the LLVM releases web site. For more information about Clang or LLVM, including information about the latest release, please check out the main please see the Clang Web Site or the LLVM Web Site. 3 Clang Documentation, Release 3.9 4 Chapter 1. Introduction CHAPTER 2 What’s New in Clang 3.9? Some of the major new features and improvements to Clang are listed here. Generic improvements to Clang as a whole or to its underlying infrastructure are described first, followed by language-specific sections with improvements to Clang’s support for those languages.
    [Show full text]
  • Hands On: C Programming and Unix Application Design: UNIX System Calls and Subroutines Using C
    Hands On: C Programming and Unix Application Design: UNIX System Calls and Subroutines using C c A. D. Marshall 1998-2004 ii Contents 1 C/C++ Program Compilation 1 1.1 Creating, Compiling and Running Your Program . 1 1.1.1 Creating the program . 1 1.1.2 Compilation . 2 1.1.3 Running the program . 3 1.2 The C Compilation Model . 3 1.2.1 The Preprocessor . 3 1.2.2 C Compiler . 5 1.2.3 Assembler . 5 1.2.4 Link Editor . 5 1.2.5 Some Useful Compiler Options . 5 1.2.6 Using Libraries . 6 1.2.7 UNIX Library Functions . 7 1.2.8 Finding Information about Library Functions . 7 1.3 Lint | A C program verifier . 8 1.4 Exercises . 9 2 C Basics 11 2.1 History of C . 11 2.2 Characteristics of C . 12 2.3 C Program Structure . 14 2.4 Variables . 16 2.4.1 Defining Global Variables . 17 2.4.2 Printing Out and Inputting Variables . 19 2.5 Constants . 19 2.6 Arithmetic Operations . 20 2.7 Comparison Operators . 21 2.8 Logical Operators . 22 iii iv CONTENTS 2.9 Order of Precedence . 22 2.10 Exercises . 24 3 Conditionals 27 3.1 The if statement . 27 3.2 The ? operator . 28 3.3 The switch statement . 29 3.4 Exercises . 31 4 Looping and Iteration 33 4.1 The for statement . 33 4.2 The while statement . 34 4.3 The do-while statement . 36 4.4 break and continue ....................... 37 4.5 Exercises .
    [Show full text]
  • Beginning Perl
    www.it-ebooks.info www.it-ebooks.info ffirs.indd ii 8/9/12 2:02 PM BEGINNING PERL INTRODUCTION . xxiii CHAPTER 1 What Is Perl? . .1 CHAPTER 2 Understanding the CPAN . 25 CHAPTER 3 Variables . .41 CHAPTER 4 Working with Data . 83 CHAPTER 5 Control Flow . 125 CHAPTER 6 References . 157 CHAPTER 7 Subroutines . 175 CHAPTER 8 Regular Expressions . 219 CHAPTER 9 Files and Directories . 249 CHAPTER 10 sort, map, and grep . 287 CHAPTER 11 Packages and Modules . 315 CHAPTER 12 Object Oriented Perl . 353 CHAPTER 13 Moose . 399 CHAPTER 14 Testing . 439 CHAPTER 15 The Interwebs . 481 CHAPTER 16 Databases . 523 CHAPTER 17 Plays Well with Others. 545 CHAPTER 18 Common Tasks . 567 CHAPTER 19 The Next Steps . .611 APPENDIX Answers to Exercises . 655 INDEX . 695 www.it-ebooks.info ffirs.indd i 8/9/12 2:02 PM www.it-ebooks.info ffirs.indd ii 8/9/12 2:02 PM BEGINNING Perl www.it-ebooks.info ffirs.indd iii 8/9/12 2:02 PM www.it-ebooks.info ffirs.indd iv 8/9/12 2:02 PM BEGINNING Perl Curtis “Ovid” Poe John Wiley & Sons, Inc. www.it-ebooks.info ffirs.indd v 8/9/12 2:02 PM Beginning Perl Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 w w w.wiley.com Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-01384-7 ISBN: 978-1-118-22187-7 (ebk) ISBN: 978-1-118-23563-8 (ebk) ISBN: 978-1-118-26051-7 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.
    [Show full text]