From mexas@bristol.ac.uk  Sun Jun 16 20:47:33 2013
Return-Path: <mexas@bristol.ac.uk>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 1B6FD39F
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 16 Jun 2013 20:47:33 +0000 (UTC)
	(envelope-from mexas@bristol.ac.uk)
Received: from mail-relay1.isys.bris.ac.uk (mail-relay1.isys.bris.ac.uk [137.222.7.2])
	by mx1.freebsd.org (Postfix) with ESMTP id 9BF571861
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 16 Jun 2013 20:47:32 +0000 (UTC)
Received: from ncsc.bris.ac.uk ([137.222.10.41])
	by tigh.isys.bris.ac.uk with esmtp (Exim 4.72)
	(envelope-from <mexas@bristol.ac.uk>)
	id 1UoJNP-0004KN-TJ
	for FreeBSD-gnats-submit@freebsd.org; Sun, 16 Jun 2013 21:16:39 +0100
Received: from cpc2-aztw9-0-0-cust169.18-1.cable.virginmedia.com ([77.97.103.170] helo=zzz.men.bris.ac.uk)
	by ncsc.bris.ac.uk with esmtpsa (TLSv1:AES256-SHA:256)
	(Exim 4.72)
	(envelope-from <mexas@bris.ac.uk>)
	id 1UoJNP-0000eK-CQ
	for FreeBSD-gnats-submit@freebsd.org; Sun, 16 Jun 2013 21:16:39 +0100
Received: from zzz.men.bris.ac.uk (localhost [127.0.0.1])
	by zzz.men.bris.ac.uk (8.14.7/8.14.6) with ESMTP id r5GKGcm2096709
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 16 Jun 2013 21:16:38 +0100 (BST)
	(envelope-from mexas@zzz.men.bris.ac.uk)
Received: (from mexas@localhost)
	by zzz.men.bris.ac.uk (8.14.7/8.14.6/Submit) id r5GKGcoo096708;
	Sun, 16 Jun 2013 21:16:38 +0100 (BST)
	(envelope-from mexas)
Message-Id: <201306162016.r5GKGcoo096708@zzz.men.bris.ac.uk>
Date: Sun, 16 Jun 2013 21:16:38 +0100 (BST)
From: Anton Shterenlikht <mexas@bristol.ac.uk>
Reply-To: Anton Shterenlikht <mexas@bristol.ac.uk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: xorg-server built with clang does not work, needs USE_GCC=any 
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         179625
>Category:       ports
>Synopsis:       x11-servers/xorg-server built with clang does not work, needs USE_GCC=any
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-x11
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun 16 20:50:00 UTC 2013
>Closed-Date:    Mon Jun 17 21:55:14 UTC 2013
>Last-Modified:  Tue Jun 18 08:40:01 UTC 2013
>Originator:     Anton Shterenlikht
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
University of Bristol
>Environment:
System: FreeBSD zzz.men.bris.ac.uk 10.0-CURRENT FreeBSD 10.0-CURRENT #4 r249781: Tue Apr 23 07:39:34 BST 2013 root@zzz.men.bris.ac.uk:/usr/obj/usr/src/sys/MINKY amd64


	
>Description:

Briefly:
********

If x11-servers/xorg-server is built with clang (default),
it does not work, i.e. :

(EE) Jun 16 21:05:31 NVIDIA(0): Failed to initialize default colormap

Full details:
*************

I have this graphics card:

vgapci0@pci0:1:0:0:     class=0x030000 card=0x20d917aa chip=0x040c10de rev=0xa1 hdr=0x00
    vendor     = 'NVIDIA Corporation'
    device     = 'G84M [Quadro FX 570M]'
    class      = display
    subclass   = VGA

I built xorg-server from ports, using clang as the default compiler.

X -configure runs fine, producing /root/xorg.conf.new as:

Section "ServerLayout"
	Identifier     "X.org Configured"
	Screen      0  "Screen0" 0 0
	InputDevice    "Mouse0" "CorePointer"
	InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
	ModulePath   "/usr/local/lib/xorg/modules"
	FontPath     "/usr/local/lib/X11/fonts/misc/"
	FontPath     "/usr/local/lib/X11/fonts/TTF/"
	FontPath     "/usr/local/lib/X11/fonts/OTF"
	FontPath     "/usr/local/lib/X11/fonts/Type1/"
	FontPath     "/usr/local/lib/X11/fonts/100dpi/"
	FontPath     "/usr/local/lib/X11/fonts/75dpi/"
EndSection

Section "Module"
	Load  "extmod"
	Load  "record"
	Load  "dbe"
	Load  "dri"
	Load  "dri2"
	Load  "glx"
EndSection

Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
EndSection

Section "InputDevice"
	Identifier  "Mouse0"
	Driver      "mouse"
	Option	    "Protocol" "auto"
	Option	    "Device" "/dev/sysmouse"
	Option	    "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
	Identifier   "Monitor0"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"
EndSection

Section "Device"
	Identifier  "Card0"
	Driver      "nvidia"
	VendorName  "NVIDIA Corporation"
	BoardName   "G84GLM [Quadro FX 570M]"
	BusID       "PCI:1:0:0"
EndSection

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
	SubSection "Display"
		Viewport   0 0
		Depth     1
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     4
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     8
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     15
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     16
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     24
	EndSubSection
EndSection


Then

X -config /root/xorg.conf.new -retro

gives this error:

X.Org X Server 1.7.7
Release Date: 2010-05-04
X Protocol Version 11, Revision 0
Build Operating System: FreeBSD 10.0-CURRENT amd64 
Current Operating System: FreeBSD zzz.men.bris.ac.uk 10.0-CURRENT FreeBSD 10.0-CURRENT #4 r249781: Tue Apr 23 07:39:34 BST 2013     root@zzz.men.bris.ac.uk:/usr/obj/usr/src/sys/MINKY amd64
Build Date: 16 June 2013  09:02:14PM
 
Current version of pixman: 0.28.2
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sun Jun 16 21:05:25 2013
(++) Using config file: "/root/xorg.conf.new"
(==) ServerLayout "X.org Configured"
(**) |-->Screen "Screen0" (0)
(**) |   |-->Monitor "Monitor0"
(**) |   |-->Device "Card0"
(**) |-->Input Device "Mouse0"
(**) |-->Input Device "Keyboard0"
(==) Automatically adding devices
(==) Automatically enabling devices
(**) FontPath set to:
	/usr/local/lib/X11/fonts/misc/,
	/usr/local/lib/X11/fonts/TTF/,
	/usr/local/lib/X11/fonts/OTF,
	/usr/local/lib/X11/fonts/Type1/,
	/usr/local/lib/X11/fonts/100dpi/,
	/usr/local/lib/X11/fonts/75dpi/,
	/usr/local/lib/X11/fonts/misc/,
	/usr/local/lib/X11/fonts/TTF/,
	/usr/local/lib/X11/fonts/OTF,
	/usr/local/lib/X11/fonts/Type1/,
	/usr/local/lib/X11/fonts/100dpi/,
	/usr/local/lib/X11/fonts/75dpi/
(**) ModulePath set to "/usr/local/lib/xorg/modules"
(WW) AllowEmptyInput is on, devices using drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.
(WW) Disabling Mouse0
(WW) Disabling Keyboard0
(II) Loader magic: 0x7b6a50
(II) Module ABI versions:
	X.Org ANSI C Emulation: 0.4
	X.Org Video Driver: 6.0
	X.Org XInput driver : 7.0
	X.Org Server Extension : 2.0
(--) Using syscons driver with X support (version 2.0)
(--) using VT number 9

(--) PCI:*(0:1:0:0) 10de:040c:17aa:20d9 NVIDIA Corporation G84GLM [Quadro FX 570M] rev 161, Mem @ 0xd6000000/16777216, 0xe0000000/268435456, 0xd4000000/33554432, I/O @ 0x00002000/128, BIOS @ 0x????????/65536
(II) "extmod" will be loaded. This was enabled by default and also specified in the config file.
(II) "dbe" will be loaded. This was enabled by default and also specified in the config file.
(II) "glx" will be loaded. This was enabled by default and also specified in the config file.
(II) "record" will be loaded. This was enabled by default and also specified in the config file.
(II) "dri" will be loaded. This was enabled by default and also specified in the config file.
(II) "dri2" will be loaded. This was enabled by default and also specified in the config file.
(II) LoadModule: "extmod"
(II) Loading /usr/local/lib/xorg/modules/extensions/libextmod.so
(II) Module extmod: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.0.0
	Module class: X.Org Server Extension
	ABI class: X.Org Server Extension, version 2.0
(II) Loading extension MIT-SCREEN-SAVER
(II) Loading extension XFree86-VidModeExtension
(II) Loading extension XFree86-DGA
(II) Loading extension DPMS
(II) Loading extension XVideo
(II) Loading extension XVideo-MotionCompensation
(II) Loading extension X-Resource
(II) LoadModule: "record"
(II) Loading /usr/local/lib/xorg/modules/extensions/librecord.so
(II) Module record: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.13.0
	Module class: X.Org Server Extension
	ABI class: X.Org Server Extension, version 2.0
(II) Loading extension RECORD
(II) LoadModule: "dbe"
(II) Loading /usr/local/lib/xorg/modules/extensions/libdbe.so
(II) Module dbe: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.0.0
	Module class: X.Org Server Extension
	ABI class: X.Org Server Extension, version 2.0
(II) Loading extension DOUBLE-BUFFER
(II) LoadModule: "dri"
(II) Loading /usr/local/lib/xorg/modules/extensions/libdri.so
(II) Module dri: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.0.0
	ABI class: X.Org Server Extension, version 2.0
(II) Loading extension XFree86-DRI
(II) LoadModule: "dri2"
(II) Loading /usr/local/lib/xorg/modules/extensions/libdri2.so
(II) Module dri2: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.1.0
	ABI class: X.Org Server Extension, version 2.0
(II) Loading extension DRI2
(II) LoadModule: "glx"
(II) Loading /usr/local/lib/xorg/modules/extensions/libglx.so
(II) Module glx: vendor="NVIDIA Corporation"
	compiled for 4.0.2, module version = 1.0.0
	Module class: X.Org Server Extension
(II) NVIDIA GLX Module  310.44  Wed Mar 27 15:00:45 PDT 2013
(II) Loading extension GLX
(II) LoadModule: "nvidia"
(II) Loading /usr/local/lib/xorg/modules/drivers/nvidia_drv.so
(II) Module nvidia: vendor="NVIDIA Corporation"
	compiled for 4.0.2, module version = 1.0.0
	Module class: X.Org Video Driver
(II) NVIDIA dlloader X Driver  310.44  Wed Mar 27 14:44:32 PDT 2013
(II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
(II) Primary Device is: PCI 01@00:00:0
(II) Loading sub module "wfb"
(II) LoadModule: "wfb"
(II) Loading /usr/local/lib/xorg/modules/libwfb.so
(II) Module wfb: vendor="X.Org Foundation"
	compiled for 1.7.7, module version = 1.0.0
	ABI class: X.Org ANSI C Emulation, version 0.4
(II) Loading sub module "ramdac"
(II) LoadModule: "ramdac"
(II) Module "ramdac" already built-in
(WW) VGA arbiter: cannot open kernel arbiter, no multi-card support
(==) NVIDIA(0): Depth 24, (==) framebuffer bpp 32
(==) NVIDIA(0): RGB weight 888
(==) NVIDIA(0): Default visual is TrueColor
(==) NVIDIA(0): Using gamma correction (1.0, 1.0, 1.0)
(**) Jun 16 21:05:25 NVIDIA(0): Enabling 2D acceleration
(II) Jun 16 21:05:29 NVIDIA(0): NVIDIA GPU Quadro FX 570M (G84GL) at PCI:1:0:0 (GPU-0)
(--) Jun 16 21:05:29 NVIDIA(0): Memory: 524288 kBytes
(--) Jun 16 21:05:29 NVIDIA(0): VideoBIOS: 60.84.51.00.00
(II) Jun 16 21:05:29 NVIDIA(0): Detected PCI Express Link width: 16X
(--) Jun 16 21:05:29 NVIDIA(0): Valid display device(s) on Quadro FX 570M at PCI:1:0:0
(--) Jun 16 21:05:29 NVIDIA(0):     CRT-0
(--) Jun 16 21:05:29 NVIDIA(0):     IBM (DFP-0) (connected)
(--) Jun 16 21:05:29 NVIDIA(0):     DFP-1
(--) Jun 16 21:05:29 NVIDIA(0): CRT-0: 400.0 MHz maximum pixel clock
(--) Jun 16 21:05:29 NVIDIA(0): IBM (DFP-0): 330.0 MHz maximum pixel clock
(--) Jun 16 21:05:29 NVIDIA(0): IBM (DFP-0): Internal Dual Link LVDS
(--) Jun 16 21:05:29 NVIDIA(0): DFP-1: 330.0 MHz maximum pixel clock
(--) Jun 16 21:05:29 NVIDIA(0): DFP-1: Internal Single Link TMDS
(**) Jun 16 21:05:29 NVIDIA(0): Using HorizSync/VertRefresh ranges from the EDID for display
(**) Jun 16 21:05:29 NVIDIA(0):     device IBM (DFP-0) (Using EDID frequencies has been
(**) Jun 16 21:05:29 NVIDIA(0):     enabled on all display devices.)
(==) Jun 16 21:05:29 NVIDIA(0): 
(==) Jun 16 21:05:29 NVIDIA(0): No modes were requested; the default mode "nvidia-auto-select"
(==) Jun 16 21:05:29 NVIDIA(0):     will be used as the requested mode.
(==) Jun 16 21:05:29 NVIDIA(0): 
(II) Jun 16 21:05:29 NVIDIA(0): Validated MetaModes:
(II) Jun 16 21:05:29 NVIDIA(0):     "DFP-0:nvidia-auto-select"
(II) Jun 16 21:05:29 NVIDIA(0): Virtual screen size determined to be 1680 x 1050
(--) Jun 16 21:05:31 NVIDIA(0): DPI set to (129, 127); computed from "UseEdidDpi" X config
(--) Jun 16 21:05:31 NVIDIA(0):     option
(WW) Jun 16 21:05:31 NVIDIA(0): UBB is incompatible with the Composite extension.  Disabling
(WW) Jun 16 21:05:31 NVIDIA(0):     UBB.
(--) Depth 24 pixmap format is 32 bpp
(II) Jun 16 21:05:31 NVIDIA: Reserving 768.00 MB of virtual memory for indirect memory
(II) Jun 16 21:05:31 NVIDIA:     access.
(II) Jun 16 21:05:31 NVIDIA(0): Setting mode "DFP-0:nvidia-auto-select"
(II) Loading extension NV-GLX
(==) NVIDIA(0): Disabling shared memory pixmaps
(==) NVIDIA(0): Backing store disabled
(==) NVIDIA(0): Silken mouse enabled
(EE) Jun 16 21:05:31 NVIDIA(0): Failed to initialize default colormap
(EE) NVIDIA(0):  *** Aborting ***

Fatal server error:
AddScreen/ScreenInit failed for driver 0


Please consult the The X.Org Foundation support 
	 at http://wiki.x.org
 for help. 
Please also check the log file at "/var/log/Xorg.0.log" for additional information.

	
>How-To-Repeat:
	
>Fix:

Rebuilding xorg-server with USE_GCC=any helps.

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-amd64->freebsd-x11 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Jun 16 23:57:46 UTC 2013 
Responsible-Changed-Why:  
reclassify and assign. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=179625 

From: Dimitry Andric <dim@FreeBSD.org>
To: bug-followup@FreeBSD.org, mexas@bristol.ac.uk
Cc:  
Subject: Re: ports/179625: x11-servers/xorg-server built with clang does not
 work, needs USE_GCC=any
Date: Mon, 17 Jun 2013 13:13:40 +0200

 This is a multi-part message in MIME format.
 --------------040606090100040907040001
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 As Jung-uk Kim points out in his reply to the thread about this bug on
 -current <http://docs.freebsd.org/cgi/mid.cgi?51BB5F3A.60504>, this may
 be due to a clang optimizer bug, specifically LLVM PR 16130
 <http://llvm.org/bugs/show_bug.cgi?id=16130>.
 
 Can you please verify it is exactly this bug, by applying the attached
 patch to your r249781 tree (I assume you have not yet upgraded), then
 rebuild clang by doing:
 
    cd /usr/src/lib/clang && make
    cd /usr/src/usr.bin/clang && make && sudo make install
 
 After the patched clang has been installed, rebuild your xorg-server
 without the USE_GCC=any setting, and check if the startup problem was
 resolved.
 
 -Dimitry
 
 --------------040606090100040907040001
 Content-Type: text/x-diff;
  name="llvm-pr16130.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="llvm-pr16130.diff"
 
 Index: contrib/llvm/include/llvm/Analysis/ScalarEvolution.h
 ===================================================================
 --- contrib/llvm/include/llvm/Analysis/ScalarEvolution.h	(revision 249781)
 +++ contrib/llvm/include/llvm/Analysis/ScalarEvolution.h	(working copy)
 @@ -453,7 +453,8 @@ namespace llvm {
      ExitLimit ComputeExitLimitFromCond(const Loop *L,
                                         Value *ExitCond,
                                         BasicBlock *TBB,
 -                                       BasicBlock *FBB);
 +                                       BasicBlock *FBB,
 +                                       bool IsSubExpr);
  
      /// ComputeExitLimitFromICmp - Compute the number of times the backedge of
      /// the specified loop will execute if its exit condition were a conditional
 @@ -461,7 +462,8 @@ namespace llvm {
      ExitLimit ComputeExitLimitFromICmp(const Loop *L,
                                         ICmpInst *ExitCond,
                                         BasicBlock *TBB,
 -                                       BasicBlock *FBB);
 +                                       BasicBlock *FBB,
 +                                       bool IsSubExpr);
  
      /// ComputeLoadConstantCompareExitLimit - Given an exit condition
      /// of 'icmp op load X, cst', try to see if we can compute the
 @@ -483,7 +485,7 @@ namespace llvm {
      /// HowFarToZero - Return the number of times an exit condition comparing
      /// the specified value to zero will execute.  If not computable, return
      /// CouldNotCompute.
 -    ExitLimit HowFarToZero(const SCEV *V, const Loop *L);
 +    ExitLimit HowFarToZero(const SCEV *V, const Loop *L, bool IsSubExpr);
  
      /// HowFarToNonZero - Return the number of times an exit condition checking
      /// the specified value for nonzero will execute.  If not computable, return
 @@ -495,7 +497,7 @@ namespace llvm {
      /// computable, return CouldNotCompute. isSigned specifies whether the
      /// less-than is signed.
      ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
 -                               const Loop *L, bool isSigned);
 +                               const Loop *L, bool isSigned, bool IsSubExpr);
  
      /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
      /// (which may not be an immediate predecessor) which has exactly one
 Index: contrib/llvm/lib/Analysis/ScalarEvolution.cpp
 ===================================================================
 --- contrib/llvm/lib/Analysis/ScalarEvolution.cpp	(revision 249781)
 +++ contrib/llvm/lib/Analysis/ScalarEvolution.cpp	(working copy)
 @@ -3937,10 +3937,19 @@ const SCEV *ScalarEvolution::createSCEV(Value *V)
  /// before taking the branch. For loops with multiple exits, it may not be the
  /// number times that the loop header executes because the loop may exit
  /// prematurely via another branch.
 +///
 +/// FIXME: We conservatively call getBackedgeTakenCount(L) instead of
 +/// getExitCount(L, ExitingBlock) to compute a safe trip count considering all
 +/// loop exits. getExitCount() may return an exact count for this branch
 +/// assuming no-signed-wrap. The number of well-defined iterations may actually
 +/// be higher than this trip count if this exit test is skipped and the loop
 +/// exits via a different branch. Ideally, getExitCount() would know whether it
 +/// depends on a NSW assumption, and we would only fall back to a conservative
 +/// trip count in that case.
  unsigned ScalarEvolution::
 -getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock) {
 +getSmallConstantTripCount(Loop *L, BasicBlock */*ExitingBlock*/) {
    const SCEVConstant *ExitCount =
 -    dyn_cast<SCEVConstant>(getExitCount(L, ExitingBlock));
 +    dyn_cast<SCEVConstant>(getBackedgeTakenCount(L));
    if (!ExitCount)
      return 0;
  
 @@ -3967,8 +3976,8 @@ unsigned ScalarEvolution::
  /// As explained in the comments for getSmallConstantTripCount, this assumes
  /// that control exits the loop via ExitingBlock.
  unsigned ScalarEvolution::
 -getSmallConstantTripMultiple(Loop *L, BasicBlock *ExitingBlock) {
 -  const SCEV *ExitCount = getExitCount(L, ExitingBlock);
 +getSmallConstantTripMultiple(Loop *L, BasicBlock */*ExitingBlock*/) {
 +  const SCEV *ExitCount = getBackedgeTakenCount(L);
    if (ExitCount == getCouldNotCompute())
      return 1;
  
 @@ -3997,7 +4006,7 @@ unsigned ScalarEvolution::
  }
  
  // getExitCount - Get the expression for the number of loop iterations for which
 -// this loop is guaranteed not to exit via ExitintBlock. Otherwise return
 +// this loop is guaranteed not to exit via ExitingBlock. Otherwise return
  // SCEVCouldNotCompute.
  const SCEV *ScalarEvolution::getExitCount(Loop *L, BasicBlock *ExitingBlock) {
    return getBackedgeTakenInfo(L).getExact(ExitingBlock, this);
 @@ -4382,26 +4391,36 @@ ScalarEvolution::ComputeExitLimit(const Loop *L, B
    // Proceed to the next level to examine the exit condition expression.
    return ComputeExitLimitFromCond(L, ExitBr->getCondition(),
                                    ExitBr->getSuccessor(0),
 -                                  ExitBr->getSuccessor(1));
 +                                  ExitBr->getSuccessor(1),
 +                                  /*IsSubExpr=*/false);
  }
  
  /// ComputeExitLimitFromCond - Compute the number of times the
  /// backedge of the specified loop will execute if its exit condition
  /// were a conditional branch of ExitCond, TBB, and FBB.
 +///
 +/// @param IsSubExpr is true if ExitCond does not directly control the exit
 +/// branch. In this case, we cannot assume that the loop only exits when the
 +/// condition is true and cannot infer that failing to meet the condition prior
 +/// to integer wraparound results in undefined behavior.
  ScalarEvolution::ExitLimit
  ScalarEvolution::ComputeExitLimitFromCond(const Loop *L,
                                            Value *ExitCond,
                                            BasicBlock *TBB,
 -                                          BasicBlock *FBB) {
 +                                          BasicBlock *FBB,
 +                                          bool IsSubExpr) {
    // Check if the controlling expression for this loop is an And or Or.
    if (BinaryOperator *BO = dyn_cast<BinaryOperator>(ExitCond)) {
      if (BO->getOpcode() == Instruction::And) {
        // Recurse on the operands of the and.
 -      ExitLimit EL0 = ComputeExitLimitFromCond(L, BO->getOperand(0), TBB, FBB);
 -      ExitLimit EL1 = ComputeExitLimitFromCond(L, BO->getOperand(1), TBB, FBB);
 +      bool EitherMayExit = L->contains(TBB);
 +      ExitLimit EL0 = ComputeExitLimitFromCond(L, BO->getOperand(0), TBB, FBB,
 +                                               IsSubExpr || EitherMayExit);
 +      ExitLimit EL1 = ComputeExitLimitFromCond(L, BO->getOperand(1), TBB, FBB,
 +                                               IsSubExpr || EitherMayExit);
        const SCEV *BECount = getCouldNotCompute();
        const SCEV *MaxBECount = getCouldNotCompute();
 -      if (L->contains(TBB)) {
 +      if (EitherMayExit) {
          // Both conditions must be true for the loop to continue executing.
          // Choose the less conservative count.
          if (EL0.Exact == getCouldNotCompute() ||
 @@ -4429,11 +4448,14 @@ ScalarEvolution::ComputeExitLimitFromCond(const Lo
      }
      if (BO->getOpcode() == Instruction::Or) {
        // Recurse on the operands of the or.
 -      ExitLimit EL0 = ComputeExitLimitFromCond(L, BO->getOperand(0), TBB, FBB);
 -      ExitLimit EL1 = ComputeExitLimitFromCond(L, BO->getOperand(1), TBB, FBB);
 +      bool EitherMayExit = L->contains(FBB);
 +      ExitLimit EL0 = ComputeExitLimitFromCond(L, BO->getOperand(0), TBB, FBB,
 +                                               IsSubExpr || EitherMayExit);
 +      ExitLimit EL1 = ComputeExitLimitFromCond(L, BO->getOperand(1), TBB, FBB,
 +                                               IsSubExpr || EitherMayExit);
        const SCEV *BECount = getCouldNotCompute();
        const SCEV *MaxBECount = getCouldNotCompute();
 -      if (L->contains(FBB)) {
 +      if (EitherMayExit) {
          // Both conditions must be false for the loop to continue executing.
          // Choose the less conservative count.
          if (EL0.Exact == getCouldNotCompute() ||
 @@ -4464,7 +4486,7 @@ ScalarEvolution::ComputeExitLimitFromCond(const Lo
    // With an icmp, it may be feasible to compute an exact backedge-taken count.
    // Proceed to the next level to examine the icmp.
    if (ICmpInst *ExitCondICmp = dyn_cast<ICmpInst>(ExitCond))
 -    return ComputeExitLimitFromICmp(L, ExitCondICmp, TBB, FBB);
 +    return ComputeExitLimitFromICmp(L, ExitCondICmp, TBB, FBB, IsSubExpr);
  
    // Check for a constant condition. These are normally stripped out by
    // SimplifyCFG, but ScalarEvolution may be used by a pass which wishes to
 @@ -4490,7 +4512,8 @@ ScalarEvolution::ExitLimit
  ScalarEvolution::ComputeExitLimitFromICmp(const Loop *L,
                                            ICmpInst *ExitCond,
                                            BasicBlock *TBB,
 -                                          BasicBlock *FBB) {
 +                                          BasicBlock *FBB,
 +                                          bool IsSubExpr) {
  
    // If the condition was exit on true, convert the condition to exit on false
    ICmpInst::Predicate Cond;
 @@ -4542,7 +4565,7 @@ ScalarEvolution::ComputeExitLimitFromICmp(const Lo
    switch (Cond) {
    case ICmpInst::ICMP_NE: {                     // while (X != Y)
      // Convert to: while (X-Y != 0)
 -    ExitLimit EL = HowFarToZero(getMinusSCEV(LHS, RHS), L);
 +    ExitLimit EL = HowFarToZero(getMinusSCEV(LHS, RHS), L, IsSubExpr);
      if (EL.hasAnyInfo()) return EL;
      break;
    }
 @@ -4553,24 +4576,24 @@ ScalarEvolution::ComputeExitLimitFromICmp(const Lo
      break;
    }
    case ICmpInst::ICMP_SLT: {
 -    ExitLimit EL = HowManyLessThans(LHS, RHS, L, true);
 +    ExitLimit EL = HowManyLessThans(LHS, RHS, L, true, IsSubExpr);
      if (EL.hasAnyInfo()) return EL;
      break;
    }
    case ICmpInst::ICMP_SGT: {
      ExitLimit EL = HowManyLessThans(getNotSCEV(LHS),
 -                                             getNotSCEV(RHS), L, true);
 +                                    getNotSCEV(RHS), L, true, IsSubExpr);
      if (EL.hasAnyInfo()) return EL;
      break;
    }
    case ICmpInst::ICMP_ULT: {
 -    ExitLimit EL = HowManyLessThans(LHS, RHS, L, false);
 +    ExitLimit EL = HowManyLessThans(LHS, RHS, L, false, IsSubExpr);
      if (EL.hasAnyInfo()) return EL;
      break;
    }
    case ICmpInst::ICMP_UGT: {
      ExitLimit EL = HowManyLessThans(getNotSCEV(LHS),
 -                                             getNotSCEV(RHS), L, false);
 +                                    getNotSCEV(RHS), L, false, IsSubExpr);
      if (EL.hasAnyInfo()) return EL;
      break;
    }
 @@ -5439,7 +5462,7 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRe
  /// effectively V != 0.  We know and take advantage of the fact that this
  /// expression only being used in a comparison by zero context.
  ScalarEvolution::ExitLimit
 -ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) {
 +ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L, bool IsSubExpr) {
    // If the value is a constant
    if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
      // If the value is already zero, the branch will execute zero times.
 @@ -5537,19 +5560,20 @@ ScalarEvolution::ExitLimit
    }
  
    // If the recurrence is known not to wraparound, unsigned divide computes the
 -  // back edge count. We know that the value will either become zero (and thus
 -  // the loop terminates), that the loop will terminate through some other exit
 -  // condition first, or that the loop has undefined behavior.  This means
 -  // we can't "miss" the exit value, even with nonunit stride.
 +  // back edge count. (Ideally we would have an "isexact" bit for udiv). We know
 +  // that the value will either become zero (and thus the loop terminates), that
 +  // the loop will terminate through some other exit condition first, or that
 +  // the loop has undefined behavior.  This means we can't "miss" the exit
 +  // value, even with nonunit stride.
    //
 -  // FIXME: Prove that loops always exhibits *acceptable* undefined
 -  // behavior. Loops must exhibit defined behavior until a wrapped value is
 -  // actually used. So the trip count computed by udiv could be smaller than the
 -  // number of well-defined iterations.
 -  if (AddRec->getNoWrapFlags(SCEV::FlagNW)) {
 -    // FIXME: We really want an "isexact" bit for udiv.
 +  // This is only valid for expressions that directly compute the loop exit. It
 +  // is invalid for subexpressions in which the loop may exit through this
 +  // branch even if this subexpression is false. In that case, the trip count
 +  // computed by this udiv could be smaller than the number of well-defined
 +  // iterations.
 +  if (!IsSubExpr && AddRec->getNoWrapFlags(SCEV::FlagNW))
      return getUDivExpr(Distance, CountDown ? getNegativeSCEV(Step) : Step);
 -  }
 +
    // Then, try to solve the above equation provided that Start is constant.
    if (const SCEVConstant *StartC = dyn_cast<SCEVConstant>(Start))
      return SolveLinEquationWithOverflow(StepC->getValue()->getValue(),
 @@ -6315,9 +6339,14 @@ const SCEV *ScalarEvolution::getBECount(const SCEV
  /// HowManyLessThans - Return the number of times a backedge containing the
  /// specified less-than comparison will execute.  If not computable, return
  /// CouldNotCompute.
 +///
 +/// @param IsSubExpr is true when the LHS < RHS condition does not directly
 +/// control the branch. In this case, we can only compute an iteration count for
 +/// a subexpression that cannot overflow before evaluating true.
  ScalarEvolution::ExitLimit
  ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
 -                                  const Loop *L, bool isSigned) {
 +                                  const Loop *L, bool isSigned,
 +                                  bool IsSubExpr) {
    // Only handle:  "ADDREC < LoopInvariant".
    if (!isLoopInvariant(RHS, L)) return getCouldNotCompute();
  
 @@ -6326,10 +6355,12 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS,
      return getCouldNotCompute();
  
    // Check to see if we have a flag which makes analysis easy.
 -  bool NoWrap = isSigned ?
 -    AddRec->getNoWrapFlags((SCEV::NoWrapFlags)(SCEV::FlagNSW | SCEV::FlagNW)) :
 -    AddRec->getNoWrapFlags((SCEV::NoWrapFlags)(SCEV::FlagNUW | SCEV::FlagNW));
 -
 +  bool NoWrap = false;
 +  if (!IsSubExpr) {
 +    NoWrap = AddRec->getNoWrapFlags(
 +      (SCEV::NoWrapFlags)(((isSigned ? SCEV::FlagNSW : SCEV::FlagNUW))
 +                          | SCEV::FlagNW));
 +  }
    if (AddRec->isAffine()) {
      unsigned BitWidth = getTypeSizeInBits(AddRec->getType());
      const SCEV *Step = AddRec->getStepRecurrence(*this);
 
 --------------040606090100040907040001--

From: Anton Shterenlikht <mexas@bris.ac.uk>
To: bug-followup@FreeBSD.org, dim@FreeBSD.org, mexas@bristol.ac.uk
Cc:  
Subject: Re: ports/179625: x11-servers/xorg-server built with clang does not work, needs USE_GCC=any
Date: Mon, 17 Jun 2013 13:00:48 +0100 (BST)

 The patch applied cleanly (yes, I'm still on r249781).
 The commands you wrote also run with no problems.
 However, rebuilding xorg-server with patched clang,
 and removing USE_GCC, did not help. The X error
 is still the same:
 
 (EE) Jun 17 12:51:23 NVIDIA(0): Failed to initialize default colormap
 (EE) NVIDIA(0):  *** Aborting ***
 
 Fatal server error:
 AddScreen/ScreenInit failed for driver 0
 
 Anton

From: Paul Brewer <paul.brewer40@ntlworld.com>
To: bug-followup@FreeBSD.org, mexas@bristol.ac.uk
Cc:  
Subject: Re: ports/179625: x11-servers/xorg-server built with clang does not
 work, needs USE_GCC=any
Date: Mon, 17 Jun 2013 21:20:54 +0100

 I too have this issue.
 
 When xorg-server is compiled with clang, the following appears in /var/log/Xorg.0.log:
 
 ----------------------------------------------------------------------
 <everything looks normal up to this point>
 (II) VBoxVideo(0): Using default gamma of (1.0, 1.0, 1.0) unless 
 otherwise stated.
 (II) VBoxVideo(0): RandR 1.2 enabled, ignore the following RandR disabled 
 message.
 
 Fatal server error:
 AddScreen/ScreenInit failed for driver 0
 
 
 Please consult the The X.Org Foundation support 
 	 at http://wiki.x.org
  for help. 
 Please also check the log file at "/var/log/Xorg.0.log" for additional 
 information.
 
 Segmentation fault at address 0x290
 ----------------------------------------------------------------------
 This is in a VM, which reports the graphics adapter as:
 
 vgapci0@pci0:0:2:0:	class=0x030000 card=0x00000000 chip=0xbeef80ee 
 rev=0x00 hdr=0x00
     vendor     = 'InnoTek Systemberatung GmbH'
     device     = 'VirtualBox Graphics Adapter'
     class      = display
     subclass   = VGA

From: Dimitry Andric <dim@FreeBSD.org>
To: mexas@bristol.ac.uk
Cc: bug-followup@FreeBSD.org,
 Jung-uk Kim <jkim@FreeBSD.org>,
 Niclas Zeising <zeising@FreeBSD.org>
Subject: Re: ports/179625: x11-servers/xorg-server built with clang does not work, needs USE_GCC=any
Date: Mon, 17 Jun 2013 23:18:43 +0200

 --Apple-Mail=_C3BEED31-6A73-4D53-9F4C-B6B88549E1BB
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain;
 	charset=us-ascii
 
 On Jun 17, 2013, at 14:00, Anton Shterenlikht <mexas@bris.ac.uk> wrote:
 > The patch applied cleanly (yes, I'm still on r249781).
 > The commands you wrote also run with no problems.
 > However, rebuilding xorg-server with patched clang,
 > and removing USE_GCC, did not help. The X error
 > is still the same:
 >=20
 > (EE) Jun 17 12:51:23 NVIDIA(0): Failed to initialize default colormap
 > (EE) NVIDIA(0):  *** Aborting ***
 >=20
 > Fatal server error:
 > AddScreen/ScreenInit failed for driver 0
 
 Okay, so the optimizer was not the issue then. :-)
 
 Luckily I was able to reproduce your error, after realizing you were
 using the old X.org server (version 1.7.7).  As far as I can tell, this
 is the following bug:
 
   https://bugs.freedesktop.org/show_bug.cgi?id=3D18451
 
 which is fixed by this commit:
 
   =
 http://cgit.freedesktop.org/xorg/xserver/commit/?id=3D6dae7f3792611aace1df=
 0cca63bf50c50d93de43
 
 I'm attaching a diff for our x11-servers/xorg-server port, can you
 please try it?  E.g. from the root of your ports tree, run:
 
   patch -p0 -f -F0 -i x11-servers__xorg-server__fix-xace-callback-1.diff
 
 which should modify x11-servers/xorg-server/Makefile, and add an
 additional patch (extra-Xext-xace.c) to the files subdirectory.  Then
 rebuild and reinstall the xorg-server port.
 
 -Dimitry
 
 
 --Apple-Mail=_C3BEED31-6A73-4D53-9F4C-B6B88549E1BB
 Content-Disposition: attachment;
 	filename=x11-servers__xorg-server__fix-xace-callback-1.diff
 Content-Type: application/octet-stream;
 	name="x11-servers__xorg-server__fix-xace-callback-1.diff"
 Content-Transfer-Encoding: 7bit
 
 Index: x11-servers/xorg-server/Makefile
 ===================================================================
 --- x11-servers/xorg-server/Makefile	(revision 321017)
 +++ x11-servers/xorg-server/Makefile	(working copy)
 @@ -33,7 +33,8 @@
  		${FILESDIR}/extra-os-utils.c \
  		${FILESDIR}/extra-Xserver-hw-xfree86-os-support-bsd-sparc64_video.c \
  		${FILESDIR}/extra-Xserver-os-xprintf.c \
 -		${FILESDIR}/extra-servermd.h
 +		${FILESDIR}/extra-servermd.h \
 +		${FILESDIR}/extra-Xext-xace.c
  .endif
  
  USE_BZIP2=	yes
 Index: x11-servers/xorg-server/files/extra-Xext-xace.c
 ===================================================================
 --- x11-servers/xorg-server/files/extra-Xext-xace.c	(revision 0)
 +++ x11-servers/xorg-server/files/extra-Xext-xace.c	(working copy)
 @@ -0,0 +1,211 @@
 +--- Xext/xace.c.orig	2010-04-21 04:00:26.000000000 +0200
 ++++ Xext/xace.c	2013-06-17 23:02:08.000000000 +0200
 +@@ -87,7 +87,18 @@ void XaceHookAuditEnd(ClientPtr ptr, int
 +  */
 + int XaceHook(int hook, ...)
 + {
 +-    pointer calldata;	/* data passed to callback */
 ++    union {
 ++	XaceResourceAccessRec res;
 ++	XaceDeviceAccessRec dev;
 ++	XaceSendAccessRec send;
 ++	XaceReceiveAccessRec recv;
 ++	XaceClientAccessRec client;
 ++	XaceExtAccessRec ext;
 ++	XaceServerAccessRec server;
 ++	XaceScreenAccessRec screen;
 ++	XaceAuthAvailRec auth;
 ++	XaceKeyAvailRec key;
 ++    } u;
 +     int *prv = NULL;	/* points to return value from callback */
 +     va_list ap;		/* argument list */
 +     va_start(ap, hook);
 +@@ -99,117 +110,86 @@ int XaceHook(int hook, ...)
 +      */
 +     switch (hook)
 +     {
 +-	case XACE_RESOURCE_ACCESS: {
 +-	    XaceResourceAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.id = va_arg(ap, XID);
 +-	    rec.rtype = va_arg(ap, RESTYPE);
 +-	    rec.res = va_arg(ap, pointer);
 +-	    rec.ptype = va_arg(ap, RESTYPE);
 +-	    rec.parent = va_arg(ap, pointer);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_RESOURCE_ACCESS:
 ++	    u.res.client = va_arg(ap, ClientPtr);
 ++	    u.res.id = va_arg(ap, XID);
 ++	    u.res.rtype = va_arg(ap, RESTYPE);
 ++	    u.res.res = va_arg(ap, pointer);
 ++	    u.res.ptype = va_arg(ap, RESTYPE);
 ++	    u.res.parent = va_arg(ap, pointer);
 ++	    u.res.access_mode = va_arg(ap, Mask);
 ++	    u.res.status = Success; /* default allow */
 ++	    prv = &u.res.status;
 ++	    break;
 ++	case XACE_DEVICE_ACCESS:
 ++	    u.dev.client = va_arg(ap, ClientPtr);
 ++	    u.dev.dev = va_arg(ap, DeviceIntPtr);
 ++	    u.dev.access_mode = va_arg(ap, Mask);
 ++	    u.dev.status = Success; /* default allow */
 ++	    prv = &u.dev.status;
 ++	    break;
 ++	case XACE_SEND_ACCESS:
 ++	    u.send.client = va_arg(ap, ClientPtr);
 ++	    u.send.dev = va_arg(ap, DeviceIntPtr);
 ++	    u.send.pWin = va_arg(ap, WindowPtr);
 ++	    u.send.events = va_arg(ap, xEventPtr);
 ++	    u.send.count = va_arg(ap, int);
 ++	    u.send.status = Success; /* default allow */
 ++	    prv = &u.send.status;
 ++	    break;
 ++	case XACE_RECEIVE_ACCESS:
 ++	    u.recv.client = va_arg(ap, ClientPtr);
 ++	    u.recv.pWin = va_arg(ap, WindowPtr);
 ++	    u.recv.events = va_arg(ap, xEventPtr);
 ++	    u.recv.count = va_arg(ap, int);
 ++	    u.recv.status = Success; /* default allow */
 ++	    prv = &u.recv.status;
 ++	    break;
 ++	case XACE_CLIENT_ACCESS:
 ++	    u.client.client = va_arg(ap, ClientPtr);
 ++	    u.client.target = va_arg(ap, ClientPtr);
 ++	    u.client.access_mode = va_arg(ap, Mask);
 ++	    u.client.status = Success; /* default allow */
 ++	    prv = &u.client.status;
 ++	    break;
 ++	case XACE_EXT_ACCESS:
 ++	    u.ext.client = va_arg(ap, ClientPtr);
 ++	    u.ext.ext = va_arg(ap, ExtensionEntry*);
 ++	    u.ext.access_mode = DixGetAttrAccess;
 ++	    u.ext.status = Success; /* default allow */
 ++	    prv = &u.ext.status;
 ++	    break;
 ++	case XACE_SERVER_ACCESS:
 ++	    u.server.client = va_arg(ap, ClientPtr);
 ++	    u.server.access_mode = va_arg(ap, Mask);
 ++	    u.server.status = Success; /* default allow */
 ++	    prv = &u.server.status;
 + 	    break;
 +-	}
 +-	case XACE_DEVICE_ACCESS: {
 +-	    XaceDeviceAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.dev = va_arg(ap, DeviceIntPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_SEND_ACCESS: {
 +-	    XaceSendAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.dev = va_arg(ap, DeviceIntPtr);
 +-	    rec.pWin = va_arg(ap, WindowPtr);
 +-	    rec.events = va_arg(ap, xEventPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_RECEIVE_ACCESS: {
 +-	    XaceReceiveAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.pWin = va_arg(ap, WindowPtr);
 +-	    rec.events = va_arg(ap, xEventPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_CLIENT_ACCESS: {
 +-	    XaceClientAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.target = va_arg(ap, ClientPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_EXT_ACCESS: {
 +-	    XaceExtAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.ext = va_arg(ap, ExtensionEntry*);
 +-	    rec.access_mode = DixGetAttrAccess;
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_SERVER_ACCESS: {
 +-	    XaceServerAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 + 	case XACE_SCREEN_ACCESS:
 +-	case XACE_SCREENSAVER_ACCESS: {
 +-	    XaceScreenAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.screen = va_arg(ap, ScreenPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 +-	    break;
 +-	}
 +-	case XACE_AUTH_AVAIL: {
 +-	    XaceAuthAvailRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.authId = va_arg(ap, XID);
 +-	    calldata = &rec;
 ++	case XACE_SCREENSAVER_ACCESS:
 ++	    u.screen.client = va_arg(ap, ClientPtr);
 ++	    u.screen.screen = va_arg(ap, ScreenPtr);
 ++	    u.screen.access_mode = va_arg(ap, Mask);
 ++	    u.screen.status = Success; /* default allow */
 ++	    prv = &u.screen.status;
 ++	    break;
 ++	case XACE_AUTH_AVAIL:
 ++	    u.auth.client = va_arg(ap, ClientPtr);
 ++	    u.auth.authId = va_arg(ap, XID);
 ++	    break;
 ++	case XACE_KEY_AVAIL:
 ++	    u.key.event = va_arg(ap, xEventPtr);
 ++	    u.key.keybd = va_arg(ap, DeviceIntPtr);
 ++	    u.key.count = va_arg(ap, int);
 + 	    break;
 +-	}
 +-	case XACE_KEY_AVAIL: {
 +-	    XaceKeyAvailRec rec;
 +-	    rec.event = va_arg(ap, xEventPtr);
 +-	    rec.keybd = va_arg(ap, DeviceIntPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    calldata = &rec;
 +-	    break;
 +-	}
 +-	default: {
 ++	default:
 + 	    va_end(ap);
 + 	    return 0;	/* unimplemented hook number */
 +-	}
 +     }
 +     va_end(ap);
 +  
 +     /* call callbacks and return result, if any. */
 +-    CallCallbacks(&XaceHooks[hook], calldata);
 ++    CallCallbacks(&XaceHooks[hook], &u);
 +     return prv ? *prv : Success;
 + }
 + 
 
 --Apple-Mail=_C3BEED31-6A73-4D53-9F4C-B6B88549E1BB--

From: Jung-uk Kim <jkim@FreeBSD.org>
To: Dimitry Andric <dim@freebsd.org>
Cc: mexas@bristol.ac.uk, bug-followup@freebsd.org, 
 Niclas Zeising <zeising@freebsd.org>
Subject: Re: ports/179625: x11-servers/xorg-server built with clang does not
 work, needs USE_GCC=any
Date: Mon, 17 Jun 2013 17:46:37 -0400

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 On 2013-06-17 17:18:43 -0400, Dimitry Andric wrote:
 > Luckily I was able to reproduce your error, after realizing you
 > were using the old X.org server (version 1.7.7).  As far as I can
 > tell, this is the following bug:
 > 
 > https://bugs.freedesktop.org/show_bug.cgi?id=18451
 > 
 > which is fixed by this commit:
 > 
 > http://cgit.freedesktop.org/xorg/xserver/commit/?id=6dae7f3792611aace1df0cca63bf50c50d93de43
 ...
 
 Yes,
 > 
 that did it!  Thanks for the nice detective work!
 
 Jung-uk Kim
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iQEcBAEBAgAGBQJRv4O9AAoJECXpabHZMqHOqHoIAIzq09axU9KP+OapYffHhM0G
 LrBSLQt0eBUzAKeNAbxGCh243zmvSv8GKt503JQf01IOtUlf1C3nh2htKiskH0Gw
 5Y2hxU8obv4dQqhj2VfM2N3YshNMIwzVv+BRuR+jRZXwkO6AzhG3QetbS4j24yhl
 QgoU/9xKznqK3DG/dMS1UhiPSIBXEtPJQydQJqENOFNWF1vfLLFnyeRqlh9/CXxn
 1EsHm+Vck1c/HOID0v7yajjBazOQmlSVNqmX6YPDsaDqa4OeZ9OKFAXM9bk2Fcjf
 xXPJWiFBxHrgdVx01X2zdPSRut4pxfIBXXC70fMy2/wwdxauxgOmEMWbNkJOPm4=
 =Fm1K
 -----END PGP SIGNATURE-----
State-Changed-From-To: open->closed 
State-Changed-By: jkim 
State-Changed-When: Mon Jun 17 21:54:15 UTC 2013 
State-Changed-Why:  
Committed (r321157), thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=179625 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/179625: commit references a PR
Date: Mon, 17 Jun 2013 21:51:57 +0000 (UTC)

 Author: jkim
 Date: Mon Jun 17 21:51:48 2013
 New Revision: 321157
 URL: http://svnweb.freebsd.org/changeset/ports/321157
 
 Log:
   Add a patch to fix upstream bug 18451 for 1.7.7.
   
   https://bugs.freedesktop.org/show_bug.cgi?id=18451
   http://cgit.freedesktop.org/xorg/xserver/patch/?id=6dae7f3
   
   Analyzed by:	dim
   PR:		ports/179625
 
 Added:
   head/x11-servers/xorg-server/files/extra-Xext-xace.c   (contents, props changed)
 Modified:
   head/x11-servers/xorg-server/Makefile
 
 Modified: head/x11-servers/xorg-server/Makefile
 ==============================================================================
 --- head/x11-servers/xorg-server/Makefile	Mon Jun 17 21:37:24 2013	(r321156)
 +++ head/x11-servers/xorg-server/Makefile	Mon Jun 17 21:51:48 2013	(r321157)
 @@ -27,12 +27,13 @@ PLIST_SUB+=	OLD="@comment " NEW=""
  EXTRA_PATCHES+=	${FILESDIR}/extra-clang
  .else
  XORG_VERSION=	1.7.7
 -XORG_REVISION=	6
 +XORG_REVISION=	7
  PLIST_SUB+=	OLD="" NEW="@comment "
 -EXTRA_PATCHES+=	${FILESDIR}/extra-include_eventstr.h \
 -		${FILESDIR}/extra-os-utils.c \
 +EXTRA_PATCHES+=	${FILESDIR}/extra-Xext-xace.c \
  		${FILESDIR}/extra-Xserver-hw-xfree86-os-support-bsd-sparc64_video.c \
  		${FILESDIR}/extra-Xserver-os-xprintf.c \
 +		${FILESDIR}/extra-include_eventstr.h \
 +		${FILESDIR}/extra-os-utils.c \
  		${FILESDIR}/extra-servermd.h
  .endif
  
 
 Added: head/x11-servers/xorg-server/files/extra-Xext-xace.c
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/x11-servers/xorg-server/files/extra-Xext-xace.c	Mon Jun 17 21:51:48 2013	(r321157)
 @@ -0,0 +1,229 @@
 +From 6dae7f3792611aace1df0cca63bf50c50d93de43 Mon Sep 17 00:00:00 2001
 +From: Chris Wilson <chris@chris-wilson.co.uk>
 +Date: Tue, 10 Aug 2010 18:30:20 +0000
 +Subject: xace: Invalid reference to out-of-scope data.
 +
 +The callback data passed by reference to the hook was allocated on stack
 +within the scope of the case statement. The compiler is free to reuse
 +any of that stack space whilst making the function call so we may end up
 +passing garbage into the callback.
 +
 +References:
 +
 +  Bug 18451 - Xorg server 1.5.2 SEGV during XFixesGetCursorImage()
 +  https://bugs.freedesktop.org/show_bug.cgi?id=18451
 +
 +v2: Drop the unrelated hunk that snuck in when ammending the commit
 +message.
 +
 +Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
 +Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
 +Signed-off-by: Keith Packard <keithp@keithp.com>
 +---
 +diff --git a/Xext/xace.c b/Xext/xace.c
 +index e10d837..c757cad 100644
 +--- Xext/xace.c
 ++++ Xext/xace.c
 +@@ -87,7 +87,18 @@ void XaceHookAuditEnd(ClientPtr ptr, int result)
 +  */
 + int XaceHook(int hook, ...)
 + {
 +-    pointer calldata;	/* data passed to callback */
 ++    union {
 ++	XaceResourceAccessRec res;
 ++	XaceDeviceAccessRec dev;
 ++	XaceSendAccessRec send;
 ++	XaceReceiveAccessRec recv;
 ++	XaceClientAccessRec client;
 ++	XaceExtAccessRec ext;
 ++	XaceServerAccessRec server;
 ++	XaceScreenAccessRec screen;
 ++	XaceAuthAvailRec auth;
 ++	XaceKeyAvailRec key;
 ++    } u;
 +     int *prv = NULL;	/* points to return value from callback */
 +     va_list ap;		/* argument list */
 +     va_start(ap, hook);
 +@@ -99,117 +110,86 @@ int XaceHook(int hook, ...)
 +      */
 +     switch (hook)
 +     {
 +-	case XACE_RESOURCE_ACCESS: {
 +-	    XaceResourceAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.id = va_arg(ap, XID);
 +-	    rec.rtype = va_arg(ap, RESTYPE);
 +-	    rec.res = va_arg(ap, pointer);
 +-	    rec.ptype = va_arg(ap, RESTYPE);
 +-	    rec.parent = va_arg(ap, pointer);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_RESOURCE_ACCESS:
 ++	    u.res.client = va_arg(ap, ClientPtr);
 ++	    u.res.id = va_arg(ap, XID);
 ++	    u.res.rtype = va_arg(ap, RESTYPE);
 ++	    u.res.res = va_arg(ap, pointer);
 ++	    u.res.ptype = va_arg(ap, RESTYPE);
 ++	    u.res.parent = va_arg(ap, pointer);
 ++	    u.res.access_mode = va_arg(ap, Mask);
 ++	    u.res.status = Success; /* default allow */
 ++	    prv = &u.res.status;
 + 	    break;
 +-	}
 +-	case XACE_DEVICE_ACCESS: {
 +-	    XaceDeviceAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.dev = va_arg(ap, DeviceIntPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_DEVICE_ACCESS:
 ++	    u.dev.client = va_arg(ap, ClientPtr);
 ++	    u.dev.dev = va_arg(ap, DeviceIntPtr);
 ++	    u.dev.access_mode = va_arg(ap, Mask);
 ++	    u.dev.status = Success; /* default allow */
 ++	    prv = &u.dev.status;
 + 	    break;
 +-	}
 +-	case XACE_SEND_ACCESS: {
 +-	    XaceSendAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.dev = va_arg(ap, DeviceIntPtr);
 +-	    rec.pWin = va_arg(ap, WindowPtr);
 +-	    rec.events = va_arg(ap, xEventPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_SEND_ACCESS:
 ++	    u.send.client = va_arg(ap, ClientPtr);
 ++	    u.send.dev = va_arg(ap, DeviceIntPtr);
 ++	    u.send.pWin = va_arg(ap, WindowPtr);
 ++	    u.send.events = va_arg(ap, xEventPtr);
 ++	    u.send.count = va_arg(ap, int);
 ++	    u.send.status = Success; /* default allow */
 ++	    prv = &u.send.status;
 + 	    break;
 +-	}
 +-	case XACE_RECEIVE_ACCESS: {
 +-	    XaceReceiveAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.pWin = va_arg(ap, WindowPtr);
 +-	    rec.events = va_arg(ap, xEventPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_RECEIVE_ACCESS:
 ++	    u.recv.client = va_arg(ap, ClientPtr);
 ++	    u.recv.pWin = va_arg(ap, WindowPtr);
 ++	    u.recv.events = va_arg(ap, xEventPtr);
 ++	    u.recv.count = va_arg(ap, int);
 ++	    u.recv.status = Success; /* default allow */
 ++	    prv = &u.recv.status;
 + 	    break;
 +-	}
 +-	case XACE_CLIENT_ACCESS: {
 +-	    XaceClientAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.target = va_arg(ap, ClientPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_CLIENT_ACCESS:
 ++	    u.client.client = va_arg(ap, ClientPtr);
 ++	    u.client.target = va_arg(ap, ClientPtr);
 ++	    u.client.access_mode = va_arg(ap, Mask);
 ++	    u.client.status = Success; /* default allow */
 ++	    prv = &u.client.status;
 + 	    break;
 +-	}
 +-	case XACE_EXT_ACCESS: {
 +-	    XaceExtAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.ext = va_arg(ap, ExtensionEntry*);
 +-	    rec.access_mode = DixGetAttrAccess;
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_EXT_ACCESS:
 ++	    u.ext.client = va_arg(ap, ClientPtr);
 ++	    u.ext.ext = va_arg(ap, ExtensionEntry*);
 ++	    u.ext.access_mode = DixGetAttrAccess;
 ++	    u.ext.status = Success; /* default allow */
 ++	    prv = &u.ext.status;
 + 	    break;
 +-	}
 +-	case XACE_SERVER_ACCESS: {
 +-	    XaceServerAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_SERVER_ACCESS:
 ++	    u.server.client = va_arg(ap, ClientPtr);
 ++	    u.server.access_mode = va_arg(ap, Mask);
 ++	    u.server.status = Success; /* default allow */
 ++	    prv = &u.server.status;
 + 	    break;
 +-	}
 + 	case XACE_SCREEN_ACCESS:
 +-	case XACE_SCREENSAVER_ACCESS: {
 +-	    XaceScreenAccessRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.screen = va_arg(ap, ScreenPtr);
 +-	    rec.access_mode = va_arg(ap, Mask);
 +-	    rec.status = Success; /* default allow */
 +-	    calldata = &rec;
 +-	    prv = &rec.status;
 ++	case XACE_SCREENSAVER_ACCESS:
 ++	    u.screen.client = va_arg(ap, ClientPtr);
 ++	    u.screen.screen = va_arg(ap, ScreenPtr);
 ++	    u.screen.access_mode = va_arg(ap, Mask);
 ++	    u.screen.status = Success; /* default allow */
 ++	    prv = &u.screen.status;
 + 	    break;
 +-	}
 +-	case XACE_AUTH_AVAIL: {
 +-	    XaceAuthAvailRec rec;
 +-	    rec.client = va_arg(ap, ClientPtr);
 +-	    rec.authId = va_arg(ap, XID);
 +-	    calldata = &rec;
 ++	case XACE_AUTH_AVAIL:
 ++	    u.auth.client = va_arg(ap, ClientPtr);
 ++	    u.auth.authId = va_arg(ap, XID);
 + 	    break;
 +-	}
 +-	case XACE_KEY_AVAIL: {
 +-	    XaceKeyAvailRec rec;
 +-	    rec.event = va_arg(ap, xEventPtr);
 +-	    rec.keybd = va_arg(ap, DeviceIntPtr);
 +-	    rec.count = va_arg(ap, int);
 +-	    calldata = &rec;
 ++	case XACE_KEY_AVAIL:
 ++	    u.key.event = va_arg(ap, xEventPtr);
 ++	    u.key.keybd = va_arg(ap, DeviceIntPtr);
 ++	    u.key.count = va_arg(ap, int);
 + 	    break;
 +-	}
 +-	default: {
 ++	default:
 + 	    va_end(ap);
 + 	    return 0;	/* unimplemented hook number */
 +-	}
 +     }
 +     va_end(ap);
 +  
 +     /* call callbacks and return result, if any. */
 +-    CallCallbacks(&XaceHooks[hook], calldata);
 ++    CallCallbacks(&XaceHooks[hook], &u);
 +     return prv ? *prv : Success;
 + }
 + 
 +--
 +cgit v0.9.0.2-2-gbebe
 _______________________________________________
 svn-ports-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-ports-all
 To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
 

From: Anton Shterenlikht <mexas@bris.ac.uk>
To: bug-followup@freebsd.org
Cc:  
Subject: RE: ports/179625: x11-servers/xorg-server built with clang does not work, needs USE_GCC=any
Date: Tue, 18 Jun 2013 09:29:13 +0100 (BST)

 Yes, this fixed the issue for me too, thank you.
 
 Shall I revert the clang patch?
 
 Thanks
 
 Anton
>Unformatted:
