From 4c8b24812ddcd1dedaca343a6d4e76f91f398981 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Wed, 14 Oct 2009 18:03:49 +0000 Subject: Update clang to r84119. --- docs/DriverInternals.html | 18 +-- docs/InternalsManual.html | 7 +- docs/LanguageExtensions.html | 44 ++++++- docs/UsersManual.html | 109 ++++++++++++++++-- docs/libIndex.html | 267 +++++++++++++++++++++++++++++++++++++++++++ docs/tools/Makefile | 5 +- docs/tools/clang.pod | 48 ++++---- 7 files changed, 450 insertions(+), 48 deletions(-) create mode 100644 docs/libIndex.html (limited to 'docs') diff --git a/docs/DriverInternals.html b/docs/DriverInternals.html index a99d72cd4eb2c..a7d2da37711e9 100644 --- a/docs/DriverInternals.html +++ b/docs/DriverInternals.html @@ -240,7 +240,7 @@

Once the arguments are parsed, the tree of subprocess jobs needed for the desired compilation sequence are - constructed. This involves determing the input files and + constructed. This involves determining the input files and their types, what work is to be done on them (preprocess, compile, assemble, link, etc.), and constructing a list of Action instances for each task. The result is a list of @@ -312,7 +312,7 @@ to run. Conceptually, the driver performs a top down matching to assign Action(s) to Tools. The ToolChain is responsible for selecting the tool to perform a particular - action; once seleected the driver interacts with the tool + action; once selected the driver interacts with the tool to see if it can match additional actions (for example, by having an integrated preprocessor). @@ -397,7 +397,7 @@

The driver constructs a Compilation object for each set of command line arguments. The Driver itself is intended to be - invariant during construct of a Compilation; an IDE should be + invariant during construction of a Compilation; an IDE should be able to construct a single long lived driver instance to use for an entire build, for example.

@@ -409,7 +409,7 @@

Unified Parsing & Pipelining

-

Parsing and pipeling both occur without reference to a +

Parsing and pipelining both occur without reference to a Compilation instance. This is by design; the driver expects that both of these phases are platform neutral, with a few very well defined exceptions such as whether the platform uses a driver @@ -425,11 +425,11 @@ stop seeing some arguments the user provided, and see new ones instead).

-

For example, on Darwin -gfull gets translated into - two separate arguments, -g - and -fno-eliminate-unused-debug-symbols. Trying to - write Tool logic to do something with -gfull will not - work, because at Tools run after the arguments have been +

For example, on Darwin -gfull gets translated into two + separate arguments, -g + and -fno-eliminate-unused-debug-symbols. Trying to write Tool + logic to do something with -gfull will not work, because Tool + argument translation is done after the arguments have been translated.

A long term goal is to remove this tool chain specific diff --git a/docs/InternalsManual.html b/docs/InternalsManual.html index a4d5a057ebaa6..f39224f47dc56 100644 --- a/docs/InternalsManual.html +++ b/docs/InternalsManual.html @@ -67,6 +67,7 @@ td {

  • Constant Folding in the Clang AST
  • +
  • The Index Library
  • @@ -528,12 +529,6 @@ describe the location of the characters corresponding to the token and the location where the token was used (i.e. the macro instantiation point or the location of the _Pragma itself).

    -

    For efficiency, we only track one level of macro instantiations: if a token was -produced by multiple instantiations, we only track the source and ultimate -destination. Though we could track the intermediate instantiation points, this -would require extra bookkeeping and no known client would benefit substantially -from this.

    -

    The Clang front-end inherently depends on the location of a token being tracked correctly. If it is ever incorrect, the front-end may get confused and die. The reason for this is that the notion of the 'spelling' of a Token in diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index c855a5057a62d..9ac35e1dc2dc2 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -27,6 +27,7 @@ td {

  • Builtin Functions
  • Target-Specific Extensions @@ -264,7 +265,7 @@ builtins that we need to implement.

    __builtin_shufflevector

    -

    __builtin_shufflevector is used to expression generic vector +

    __builtin_shufflevector is used to express generic vector permutation/shuffle/swizzle operations. This builtin is also very important for the implementation of various target-specific header files like <xmmintrin.h>. @@ -310,6 +311,47 @@ with the same element type as vec1/vec2 but that has an element count equal to the number of indices specified.

    +

    Query for this feature with __has_builtin(__builtin_shufflevector).

    + + +

    __builtin_unreachable

    + + +

    __builtin_unreachable is used to indicate that a specific point in +the program cannot be reached, even if the compiler might otherwise think it +can. This is useful to improve optimization and eliminates certain warnings. +For example, without the __builtin_unreachable in the example below, +the compiler assumes that the inline asm can fall through and prints a "function +declared 'noreturn' should not return" warning. +

    + +

    Syntax:

    + +
    +__builtin_unreachable()
    +
    + +

    Example of Use:

    + +
    +void myabort(void) __attribute__((noreturn));
    +void myabort(void) {
    +    asm("int3");
    +    __builtin_unreachable();
    +}
    +
    + +

    Description:

    + +

    The __builtin_unreachable() builtin has completely undefined behavior. Since +it has undefined behavior, it is a statement that it is never reached and the +optimizer can take advantage of this to produce better code. This builtin takes +no arguments and produces a void result. +

    + +

    Query for this feature with __has_builtin(__builtin_unreachable).

    + +

    Target-Specific Extensions

    diff --git a/docs/UsersManual.html b/docs/UsersManual.html index 65415eea48d5a..20fdda72dced9 100644 --- a/docs/UsersManual.html +++ b/docs/UsersManual.html @@ -33,6 +33,12 @@ td {
  • Language and Target-Independent Features
  • @@ -362,7 +368,7 @@ by commenting them out.

    Clang provides a number of ways to control which code constructs cause it to emit errors and warning messages, and how they are displayed to the console.

    -

    Controlling How Clang Displays Diagnostics

    +

    Controlling How Clang Displays Diagnostics

    When Clang emits a diagnostic, it includes rich information in the output, and gives you fine-grain control over which information is printed. Clang has @@ -394,18 +400,64 @@ it:

    For more information please see Formatting of Diagnostics.

    -

    Controlling Which Diagnostics Clang Generates

    +

    Diagnostic Mappings

    -

    mappings: ignore, note, warning, error, fatal

    +

    All diagnostics are mapped into one of these 5 classes:

    -The two major classes are control from the command line and control via pragmas -in your code.

    +

    +

    Controlling Diagnostics via Command Line Flags

    -W flags, -pedantic, etc

    -

    pragma GCC diagnostic

    +

    Controlling Diagnostics via Pragmas

    + +

    Clang can also control what diagnostics are enabled through the use of +pragmas in the source code. This is useful for turning off specific warnings +in a section of source code. Clang supports GCC's pragma for compatibility +with existing source code, as well as several extensions.

    + +

    The pragma may control any warning that can be used from the command line. +Warnings may be set to ignored, warning, error, or fatal. The following +example code will tell Clang or GCC to ignore the -Wall warnings:

    + +
    +#pragma GCC diagnostic ignored "-Wall"
    +
    + +

    In addition to all of the functionality of provided by GCC's pragma, Clang +also allows you to push and pop the current warning state. This is particularly +useful when writing a header file that will be compiled by other people, because +you don't know what warning flags they build with.

    + +

    In the below example +-Wmultichar is ignored for only a single line of code, after which the +diagnostics return to whatever state had previously existed.

    + +
    +#pragma clang diagnostic push
    +#pragma clang diagnostic ignored "-Wmultichar"
    +
    +char b = 'df'; // no warning.
    +
    +#pragma clang diagnostic pop
    +
    + +

    The push and pop pragmas will save and restore the full diagnostic state of +the compiler, regardless of how it was set. That means that it is possible to +use push and pop around GCC compatible diagnostics and Clang will push and pop +them appropriately, while GCC will ignore the pushes and pops as unknown +pragmas. It should be noted that while Clang supports the GCC pragma, Clang and +GCC do not support the exact same set of warnings, so even when using GCC +compatible #pragmas there is no guarantee that they will have identical behaviour +on both compilers.

    Precompiled Headers

    @@ -465,6 +517,50 @@ for headers that are directly included within a source file. For example:

    test.h since test.h was included directly in the source file and not specified on the command line using -include.

    +

    Relocatable PCH Files

    +

    It is sometimes necessary to build a precompiled header from headers that +are not yet in their final, installed locations. For example, one might build a +precompiled header within the build tree that is then meant to be installed +alongside the headers. Clang permits the creation of "relocatable" precompiled +headers, which are built with a given path (into the build directory) and can +later be used from an installed location.

    + +

    To build a relocatable precompiled header, place your headers into a +subdirectory whose structure mimics the installed location. For example, if you +want to build a precompiled header for the header mylib.h that +will be installed into /usr/include, create a subdirectory +build/usr/include and place the header mylib.h into +that subdirectory. If mylib.h depends on other headers, then +they can be stored within build/usr/include in a way that mimics +the installed location.

    + +

    Building a relocatable precompiled header requires two additional arguments. +First, pass the --relocatable-pch flag to indicate that the +resulting PCH file should be relocatable. Second, pass +-isysroot /path/to/build, which makes all includes for your +library relative to the build directory. For example:

    + +
    +  # clang -x c-header --relocatable-pch -isysroot /path/to/build /path/to/build/mylib.h mylib.h.pch
    +
    + +

    When loading the relocatable PCH file, the various headers used in the PCH +file are found from the system header root. For example, mylib.h +can be found in /usr/include/mylib.h. If the headers are installed +in some other system root, the -isysroot option can be used provide +a different system root from which the headers will be based. For example, +-isysroot /Developer/SDKs/MacOSX10.4u.sdk will look for +mylib.h in +/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h.

    + +

    Relocatable precompiled headers are intended to be used in a limited number +of cases where the compilation environment is tightly controlled and the +precompiled header cannot be generated after headers have been installed. +Relocatable precompiled headers also have some performance impact, because +the difference in location between the header locations at PCH build time vs. +at the time of PCH use requires one of the PCH optimizations, +stat() caching, to be disabled. However, this change is only +likely to affect PCH files that reference a large number of headers.

    C Language Features

    @@ -500,7 +596,6 @@ variants "__asm__" and "__typeof__" are recognized in all modes.
  • The Apple "blocks" extension is recognized by default in gnu* modes on some platforms; it can be enabled in any mode with the "-fblocks" option.
  • -
  • Some warnings are different.
  • Differences between *89 and *99 modes:

    diff --git a/docs/libIndex.html b/docs/libIndex.html new file mode 100644 index 0000000000000..5693de80a8685 --- /dev/null +++ b/docs/libIndex.html @@ -0,0 +1,267 @@ + + + The Index Library + + + + + + + + + +
    + +

    The Index Library

    + +

    Table of Contents

    + + +

    Design Philosophy

    + +

    The Index library is meant to provide the basic infrastructure for + cross-translation-unit analysis and is primarily focused on indexing + related functionality. It provides an API for clients that need to + accurately map the AST nodes of the ASTContext to the locations in the source files. +It also allows them to analyze information across multiple translation units.

    + +

    As a "general rule", ASTContexts are considered the primary source of +information that a client wants about a translation unit. There will be no such class as an + "indexing database" that stores, for example, source locations of identifiers separately from ASTContext. +All the information that a client needs from a translation unit will be extracted from the ASTContext.

    + +

    Classes

    + +

    Entity

    + +

    To be able to reason about semantically the same Decls that are contained in multiple ASTContexts, the 'Entity' class was introduced. +An Entity is an ASTContext-independent "token" that can be created from a Decl (and a typename in the future) with +the purpose to "resolve" it into a Decl belonging to another ASTContext. Some examples to make the concept of Entities more clear:

    + +

    +t1.c: +

    +void foo(void);
    +void bar(void);
    +
    +

    + +

    +t2.c: +

    +void foo(void) {
    +}
    +
    +

    + +

    +Translation unit t1.c contains 2 Entities foo and bar, while t2.c contains 1 Entity foo. +Entities are uniqued in such a way that the Entity* pointer for t1.c/foo is the same as the Entity* pointer for t2.c/foo. +An Entity doesn't convey any information about the declaration, it is more like an opaque pointer used only to get the +associated Decl out of an ASTContext so that the actual information for the declaration can be accessed. +Another important aspect of Entities is that they can only be created/associated for declarations that are visible outside the +translation unit. This means that for: +

    +

    +t3.c: +

    +static void foo(void);
    +
    +

    +

    +there can be no Entity (if you ask for the Entity* of the static function foo you'll get a null pointer). +This is for 2 reasons: +

    +

    + +

    ASTLocation

    + +Encapsulates a "point" in the AST tree of the ASTContext. +It represents either a Decl*, or a Stmt* along with its immediate Decl* parent. +An example for its usage is that libIndex will provide the references of foo in the form of ASTLocations, +"pointing" at the expressions that reference foo. + +

    DeclReferenceMap

    + +Accepts an ASTContext and creates a mapping from NamedDecls to the ASTLocations that reference them (in the same ASTContext). + +

    Functions

    + +

    ResolveLocationInAST

    + +A function that accepts an ASTContext and a SourceLocation which it resolves into an ASTLocation. + +

    AST Files

    + +The precompiled headers implementation of clang (PCH) is ideal for storing an ASTContext in a compact form that +will be loaded later for AST analysis. An "AST file" refers to a translation unit that was "compiled" into a precompiled header file. + +

    index-test tool

    + +

    Usage

    + +A command-line tool that exercises the libIndex API, useful for testing its features. +As input it accepts multiple AST files (representing multiple translation units) and a few options: + +

    +

    +   -point-at  [file:line:column]
    +
    +Resolves a [file:line:column] triplet into a ASTLocation from the first AST file. If no other option is specified, it prints the ASTLocation. +It also prints a declaration's associated doxygen comment, if one is available. +

    + +

    +

    +   -print-refs
    +
    +Prints the ASTLocations that reference the declaration that was resolved out of the [file:line:column] triplet +

    + +

    +

    +   -print-defs
    +
    +Prints the ASTLocations that define the resolved declaration +

    + +

    +

    +   -print-decls
    +
    +Prints the ASTLocations that declare the resolved declaration +

    + +

    Examples

    + +

    +Here's an example of using index-test: +

    + +

    +We have 3 files, +

    + +

    +foo.h: +

    +extern int global_var;
    +
    +void foo_func(int param1);
    +void bar_func(void);
    +
    + +t1.c: +
    +#include "foo.h"
    +
    +void foo_func(int param1) {
    +  int local_var = global_var;
    +  for (int for_var = 100; for_var < 500; ++for_var) {
    +    local_var = param1 + for_var;
    +  }
    +  bar_func();
    +}
    +
    + +t2.c: +
    +#include "foo.h"
    +
    +int global_var = 10;
    +
    +void bar_func(void) {
    +  global_var += 100;
    +  foo_func(global_var);
    +}
    +
    +

    + +

    +You first get AST files out of t1.c and t2.c: + +

    +$ clang-cc -emit-pch t1.c -o t1.ast
    +$ clang-cc -emit-pch t2.c -o t2.ast
    +
    +

    + +

    +Find the ASTLocation under this position of t1.c: +

    +[...]
    +void foo_func(int param1) {
    +  int local_var = global_var;
    +                      ^
    +[...]
    +
    + +
    +$ index-test t1.ast -point-at t1.c:4:23
    +> [Decl: Var local_var | Stmt: DeclRefExpr global_var] <t1.c:4:19, t1.c:4:19>
    +
    +

    + +

    +Find the declaration: + +

    +$ index-test t1.ast -point-at t1.c:4:23 -print-decls
    +> [Decl: Var global_var] <foo.h:1:12, foo.h:1:12>
    +
    +

    + +

    +Find the references: + +

    +$ index-test t1.ast t2.ast -point-at t1.c:4:23 -print-refs
    +> [Decl: Var local_var | Stmt: DeclRefExpr global_var] <t1.c:4:19, t1.c:4:19>
    +> [Decl: Function bar_func | Stmt: DeclRefExpr global_var] <t2.c:6:3, t2.c:6:3>
    +> [Decl: Function bar_func | Stmt: DeclRefExpr global_var] <t2.c:7:12, t2.c:7:12>
    +
    +

    + +

    +Find definitions: + +

    +$ index-test t1.ast t2.ast -point-at t1.c:4:23 -print-defs
    +> [Decl: Var global_var] <t2.c:3:5, t2.c:3:18>
    +
    +

    + +
    + + + diff --git a/docs/tools/Makefile b/docs/tools/Makefile index 90eb7768f531b..12696ef0b659b 100644 --- a/docs/tools/Makefile +++ b/docs/tools/Makefile @@ -21,6 +21,7 @@ SRC_DOC_DIR= DST_HTML_DIR=html/ DST_MAN_DIR=man/man1/ DST_PS_DIR=ps/ +CLANG_VERSION := trunk # If we are in BUILD_FOR_WEBSITE mode, default to the all target. all:: html man ps @@ -39,6 +40,8 @@ else LEVEL := ../../../.. include $(LEVEL)/Makefile.common +CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER) + SRC_DOC_DIR=$(PROJ_SRC_DIR)/ DST_HTML_DIR=$(PROJ_OBJ_DIR)/ DST_MAN_DIR=$(PROJ_OBJ_DIR)/ @@ -66,7 +69,7 @@ $(DST_HTML_DIR)%.html: %.pod $(DST_HTML_DIR)/.dir --podpath=. --infile=$< --outfile=$@ --title=$* $(DST_MAN_DIR)%.1: %.pod $(DST_MAN_DIR)/.dir - pod2man --release "clang 1.0" --center="Clang Tools Documentation" $< $@ + pod2man --release "clang $(CLANG_VERSION)" --center="Clang Tools Documentation" $< $@ $(DST_PS_DIR)%.ps: $(DST_MAN_DIR)%.1 $(DST_PS_DIR)/.dir groff -Tps -man $< > $@ diff --git a/docs/tools/clang.pod b/docs/tools/clang.pod index c520f93997e53..daa7387989309 100644 --- a/docs/tools/clang.pod +++ b/docs/tools/clang.pod @@ -378,8 +378,7 @@ Show commands to run and use verbose output. =over -=item -B<-fshow-column> +=item B<-fshow-column> B<-fshow-source-location> B<-fcaret-diagnostics> B<-fdiagnostics-fixit-info> @@ -428,13 +427,14 @@ Do not search the standard system directories for include files. =cut ## TODO, but do we really want people using this stuff? -=item B<-idirafter>I -=item B<-iquote>I -=item B<-isystem>I -=item B<-iprefix>I -=item B<-iwithprefix>I -=item B<-iwithprefixbefore>I -=item B<-isysroot> +#=item B<-idirafter>I +#=item B<-iquote>I +#=item B<-isystem>I +#=item B<-iprefix>I +#=item B<-iwithprefix>I +#=item B<-iwithprefixbefore>I +#=item B<-isysroot> + =pod @@ -445,21 +445,21 @@ Do not search the standard system directories for include files. =cut ### TODO someday. -=head2 Warning Control Options -=over -=back -=head2 Code Generation and Optimization Options -=over -=back -=head2 Assembler Options -=over -=back -=head2 Linker Options -=over -=back -=head2 Static Analyzer Options -=over -=back +#=head2 Warning Control Options +#=over +#=back +#=head2 Code Generation and Optimization Options +#=over +#=back +#=head2 Assembler Options +#=over +#=back +#=head2 Linker Options +#=over +#=back +#=head2 Static Analyzer Options +#=over +#=back =pod -- cgit v1.3