Bug 183064

Summary: editors/emacs-nox11 port won't build with CLANG
Product: Ports & Packages Reporter: Mark Willson <cdr.nil>
Component: Individual Port(s)Assignee: Ashish SHUKLA <ashish>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Mark Willson 2013-10-17 17:40:00 UTC
Build failed with:

  if test "no" = "yes"; then \
  rm -f bootstrap-emacs; \
  ln temacs bootstrap-emacs; \
  else \
  `/bin/pwd`/temacs --batch --load loadup bootstrap || exit 1; \
  test "X" = X ||  -zex emacs; \
  mv -f emacs bootstrap-emacs; \
  fi
  Loading loadup.el (source)...
  Using load-path (/usr/ports/editors/emacs-nox11/work/emacs-24.3/lisp \
   /usr/ports/editors/emacs-nox11/work/emacs-24.3/lisp/emacs-lisp \
   /usr/ports/editors/emacs-nox11/work/emacs-24.3/lisp/language \
   /usr/ports/editors/emacs-nox11/work/emacs-24.3/lisp/international \
   /usr/ports/editors/emacs-nox11/work/emacs-24.3/lisp/textmodes)
  Loading emacs-lisp/byte-run...
  Loading emacs-lisp/backquote...
  Loading subr...
  Loading version...
  Segmentation fault (core dumped)
  gmake[2]: *** [bootstrap-emacs] Error 1
  gmake[2]: Leaving directory `/usr/ports/editors/emacs-nox11/work/emacs-24.3/src'
  gmake[1]: *** [src] Error 2
  gmake[1]: Leaving directory `/usr/ports/editors/emacs-nox11/work/emacs-24.3'
  ===> Compilation failed unexpectedly.
  Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
  the maintainer.
  *** Error code 1

  Stop.
  make: stopped in /usr/ports/editors/emacs-nox11

Setting MAKE_JOBS_UNSAFE=yes didn't change things. I changed CFLAGS from the default of "-O -pipe" to "-g" to obtain more info from the core dump, but the build then produced this:

  cc -nostdlib -Demacs -I. -I/usr/ports/editors/emacs-nox11/work/emacs-24.3/src
    -I../lib -I/usr/ports/editors/emacs-nox11/work/emacs-24.3/src/../lib \
    -MMD -MF deps/.d -MP     -g -march=pentiumpro   -L/usr/local/lib \
    -Wl,-rpath=/usr/lib:/usr/local/lib -Wl,-znocombreloc \
    -o temacs pre-crt0.o /usr/lib/crt1.o /usr/lib/crti.o dispnew.o frame.o \
    scroll.o xdisp.o menu.o  window.o charset.o coding.o category.o ccl.o \
    character.o chartab.o bidi.o cm.o term.o terminal.o xfaces.o    emacs.o \
    keyboard.o macros.o keymap.o sysdep.o buffer.o filelock.o insdel.o \
    marker.o minibuf.o fileio.o dired.o cmds.o casetab.o casefiddle.o \
    indent.o search.o regex.o undo.o alloc.o data.o doc.o editfns.o \
    callint.o eval.o floatfns.o fns.o font.o print.o lread.o syntax.o \
    unexelf.o bytecode.o process.o gnutls.o callproc.o region-cache.o \
    sound.o atimer.o doprnt.o intervals.o textprop.o composite.o xml.o \
    profiler.o         terminfo.o lastfile.o gmalloc.o   vm-limit.o   \
    ../lib/libgnu.a            -lrt  -lexecinfo    \
    -lutil -lncurses         -lpthread   -lm -lgcc -lc -lgcc /usr/lib/crtn.o
  xdisp.o: In function `get_next_display_element':
  /usr/ports/editors/emacs-nox11/work/emacs-24.3/src/xdisp.c:6887: 
  undefined reference to `face_for_font'
  cc: error: linker command failed with exit code 1 (use -v to see invocation)
  gmake[2]: *** [temacs] Error 1
  gmake[2]: Leaving directory `/usr/ports/editors/emacs-nox11/work/emacs-24.3/src'
  gmake[1]: *** [src] Error 2
  gmake[1]: Leaving directory `/usr/ports/editors/emacs-nox11/work/emacs-24.3'
  ===> Compilation failed unexpectedly.
  Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
  the maintainer.
  *** Error code 1

This has been recently reported (http://emacs.1067599.n5.nabble.com/bug-15484-24-3-50-link-error-xdisp-c-uses-windowing-functions-for-terminal-only-case-td298573.html).  I applied the changes to xdisp.c from trunk revision 114482 and the build succeeded.

Fix: 

Apply the following changes to /usr/ports/editors/emacs-nox11/work/emacs-24.3/src/xdisp.c

  # diff /home/mark/dev/emacs-24.3/src/xdisp.c work/emacs-24.3/src/xdisp.c
  6872c6872
  < #ifdef HAVE_WINDOW_SYSTEM
  ---
  >
  6913c6913
  < #endif /* HAVE_WINDOW_SYSTEM */
How-To-Repeat: # cd /usr/ports/editors/emacs-nox11
# echo "CLAGS=-O -pipe" >>/etc/make.conf
# make
Comment 1 Edwin Groothuis freebsd_committer 2013-10-18 04:05:37 UTC
Responsible Changed
From-To: freebsd-ports-bugs->ashish

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Mark Willson 2013-11-03 11:43:02 UTC
Ashish,

Thanks for the response.

Yes, both diffs apply cleanly on my i386 version.

BTW, little choice on the email handle.  Nil had gone, so had car.nil - I
took what was left!

Best Regards,
Mark
--
Mark Willson
cdr.nil@gmail.com
http://www.hydrus.org.uk


-----Original Message-----
From: Ashish SHUKLA [mailto:ashish@FreeBSD.org] 
Sent: 02 November 2013 13:03
To: cdr.nil@gmail.com
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/183064: editors/emacs-nox11 port won't build with CLANG

Hi Mark,

Thanks for the diff. Although, I'm not able to reproduce it on my 10-BETA2
(amd64) host, but the patch seems good enough to be in tree.

I'll push it in next update, which will be soon.

If you don't mind could you test it, if the attached commit diffs works for
you? These are for ports, editors/emacs, and editors/emacs-nox11 with
staging
support, relocation of INFO_PATH to avoid conflict with texinfo,
PkgNameCollisions[1], etc. changes.

References:
[1]  https://wiki.freebsd.org/ports/PkgNameCollisions

Thanks
-- 
Ashish SHUKLA      | GPG: F682 CDCC 39DC 0FEA E116  20B6 C746 CFA9 E74F A4B0
Sent from my Emacs

P.S. nice username, (cdr 'nil) :)
Comment 3 Tim Kientzle freebsd_committer 2013-11-10 23:28:37 UTC
I=92m seeing the same crash trying to build emacs-nox11 on
FreeBSD-CURRENT r257910 on i386.

Without changing CFLAGS, the coredump from temacs shows
the following backtrace:

(gdb) bt
#0  0x08126d2d in format_time_string ()
#1  0x08126c28 in Fformat_time_string ()
#2  0x0813310b in Ffuncall ()
#3  0x08162520 in exec_byte_code ()
#4  0x08133a65 in funcall_lambda ()
#5  0x08132f52 in Ffuncall ()
#6  0x08162520 in exec_byte_code ()
#7  0x08161de8 in Fbyte_code ()
#8  0x0812fe31 in eval_sub ()
#9  0x0814d7c9 in readevalloop ()
#10 0x0814c8a6 in Fload ()
#11 0x0812fe90 in eval_sub ()
#12 0x0814d7c9 in readevalloop ()
#13 0x0814c8a6 in Fload ()
#14 0x0812fe90 in eval_sub ()
#15 0x08132783 in Feval ()
#16 0x080d224d in top_level_2 ()
#17 0x08131acd in internal_condition_case ()
#18 0x080d2211 in top_level_1 ()
#19 0x0813163a in internal_catch ()
#20 0x080c2daa in recursive_edit_1 ()
#21 0x080c2ec8 in Frecursive_edit ()
#22 0x080c1f06 in main ()


If I try to set CFLAGS=3D-g, I see the same link failure that Mark
reports (xdisp.c:6887 reference to face_for_font), but the patch
he provided doesn=92t apply for me (the string
HAVE_WINDOW_SYSTEM doesn=92t appear between
lines 5000 and 10000 in xdisp.c, though there are many,
many occurrences before and after that).

Tim
Comment 4 Ashish SHUKLA freebsd_committer 2013-11-11 02:13:10 UTC
Hi Tim,

Did you try the emacs diff I posted in the followup to this PR ? I downloaded
it and applied to the version of editors/emacs from port, and it seems to
apply fine.

The bzr revision which Mark pointed was for the trunk, so I just adapted it to
24.3.

You can also try editors/emacs* ports from following svn version URL:

https://svn.redports.org/ashish/editors/

HTH
-- 
Ashish SHUKLA      | GPG: F682 CDCC 39DC 0FEA E116  20B6 C746 CFA9 E74F A4B0
Sent from my Emacs
Comment 5 Tim Kientzle freebsd_committer 2013-11-12 16:10:04 UTC
On Nov 10, 2013, at 6:13 PM, Ashish SHUKLA <ashish@freebsd.org> wrote:

> Hi Tim,
>=20
> Did you try the emacs diff I posted in the followup to this PR ? I =
downloaded
> it and applied to the version of editors/emacs from port, and it seems =
to
> apply fine.

The patch didn=92t quite apply cleanly for me.  Some of the SVN version =
lines were different and so the initial chunks had to be applied =
manually.

When I build normally, it still segfaults in temacs.  That=92s the same =
with or without the patch.

When I try
  $ CFLAGS=3D-g make
as Mark suggested, it now seems to build okay with the patch.


> The bzr revision which Mark pointed was for the trunk, so I just =
adapted it to
> 24.3.
>=20
> You can also try editors/emacs* ports from following svn version URL:
>=20
> https://svn.redports.org/ashish/editors/

I=92ll try that and let you know...


Tim
Comment 6 Ashish SHUKLA freebsd_committer 2013-11-14 05:46:37 UTC
Hi Tim,

So does this mean build with non-optimization flags (-O) succeeds whereas
optimized build segfaults, right ?

Thanks
-- 
Ashish SHUKLA      | GPG: F682 CDCC 39DC 0FEA E116  20B6 C746 CFA9 E74F A4B0
Sent from my Emacs
Comment 7 Mark Willson 2013-11-14 09:34:44 UTC
Folks,

Sorry for the late jump-in.  Yes, specifying -O in CFLAGS makes the build
work, but resulted in the failure during bootstrap-emacs phase.  Without
-O, then the link failure occurs (undefined reference to `face_for_font').

Tim, here's the code that is commented out in xdisp.c by the
HAVE_WINDOW_SYSTEM ifdef.  Might make it easier to figure out where it goes.

#ifdef HAVE_WINDOW_SYSTEM
  /* Adjust face id for a multibyte character.  There are no multibyte
     character in unibyte text.  */
  if ((it->what == IT_CHARACTER || it->what == IT_COMPOSITION)

      && it->multibyte_p
      && success_p
      && FRAME_WINDOW_P (it->f))
    {
      struct face *face = FACE_FROM_ID (it->f, it->face_id);

      if (it->what == IT_COMPOSITION && it->cmp_it.ch >= 0)
        {
          /* Automatic composition with glyph-string.   */
          Lisp_Object gstring = composition_gstring_from_id (it->cmp_it.id);

          it->face_id = face_for_font (it->f, LGSTRING_FONT (gstring),
face);
        }
      else
        {
          ptrdiff_t pos = (it->s ? -1
                     : STRINGP (it->string) ? IT_STRING_CHARPOS (*it)
                     : IT_CHARPOS (*it));
          int c;

          if (it->what == IT_CHARACTER)
            c = it->char_to_display;
          else
            {
              struct composition *cmp = composition_table[it->cmp_it.id];
              int i;

              c = ' ';
              for (i = 0; i < cmp->glyph_len; i++)
                /* TAB in a composition means display glyphs with
                   padding space on the left or right.  */
                if ((c = COMPOSITION_GLYPH (cmp, i)) != '\t')
                  break;
            }
          it->face_id = FACE_FOR_CHAR (it->f, face, c, pos, it->string);
        }
    }
#endif /* HAVE_WINDOW_SYSTEM */
 -mark


On 14 November 2013 05:46, Ashish SHUKLA <ashish@freebsd.org> wrote:

> Hi Tim,
>
> So does this mean build with non-optimization flags (-O) succeeds whereas
> optimized build segfaults, right ?
>
> Thanks
> --
> Ashish SHUKLA      | GPG: F682 CDCC 39DC 0FEA E116  20B6 C746 CFA9 E74F
> A4B0
> Sent from my Emacs
>



-- 
Mark Willson
cdr.nil@gmail.com
http://www.hydrus.org.uk
Comment 8 Tim Kientzle freebsd_committer 2013-11-15 05:44:46 UTC
I think the link failure from face_for_font and the temacs crash might
actually be unrelated, strange as that seems.

I built emacs-nox11 with Ashish=92 patches as follows on FreeBSD-CURRENT
i386 r257485:

 $ CFLAGS=3D=91-g -O=92 make

then it crash when it tries to build the dumped emacs.

Unfortunately, temacs isn=92t built with CFLAGS; so I had to
copy the link line and add -g to get something debuggable.

I ran the resulting temacs command in gdb:

$ cd work/emacs-24.3/src
$ gdb temacs
(gdb) break format_time_string
(gdb) run =97batch =97load loadup bootstrap

then it crashes the first time it enters format_time_string
in editfns.c.

This looks like it might be a compiler bug:  The function
declares

      char buffer[4000];
      char *buf =3D buffer;

  but then crashes a few lines later at

      buf[0] =3D =91\1=92;

with buf being a NULL pointer.  I checked and it is the
first time through the while loop.  It could also be the stack
getting stomped from some other function, I suppose.

Tim
Comment 9 Mark Willson 2013-11-15 13:45:53 UTC
Tim,

My guess, FWIW, is that the CLANG optimisation is doing something that GCC
didn't do, which causes temacs to fault, but also eliminates the call to
face_for_font, allowing the build to succeed. Without optimisation the
temacs fault wouldn't happen, but now it won't compile (until the call to
face_for_font is commented out).

Anyway, glad emacs is working; failing back to vi was a pain...

-mark


On 15 November 2013 05:44, Tim Kientzle <kientzle@freebsd.org> wrote:

> I think the link failure from face_for_font and the temacs crash might
> actually be unrelated, strange as that seems.
>
> I built emacs-nox11 with Ashish patches as follows on FreeBSD-CURRENT
> i386 r257485:
>
>  $ CFLAGS=-g -O make
>
> then it crash when it tries to build the dumped emacs.
>
> Unfortunately, temacs isnt built with CFLAGS; so I had to
> copy the link line and add -g to get something debuggable.
>
> I ran the resulting temacs command in gdb:
>
> $ cd work/emacs-24.3/src
> $ gdb temacs
> (gdb) break format_time_string
> (gdb) run batch load loadup bootstrap
>
> then it crashes the first time it enters format_time_string
> in editfns.c.
>
> This looks like it might be a compiler bug:  The function
> declares
>
>       char buffer[4000];
>       char *buf = buffer;
>
>   but then crashes a few lines later at
>
>       buf[0] = \1;
>
> with buf being a NULL pointer.  I checked and it is the
> first time through the while loop.  It could also be the stack
> getting stomped from some other function, I suppose.
>
> Tim
>
>



-- 
Mark Willson
cdr.nil@gmail.com
http://www.hydrus.org.uk
Comment 10 Ashish SHUKLA freebsd_committer 2013-12-07 14:07:27 UTC
I did some debugging and filed following bug report with clang/LLVM bug
tracker:

http://llvm.org/bugs/show_bug.cgi?id=18171

In the meantime, I'll just make emacs* ports use 'gcc' on 'i386' platforms.

Thanks
-- 
Ashish SHUKLA      | GPG: F682 CDCC 39DC 0FEA E116  20B6 C746 CFA9 E74F A4B0
Sent from my Emacs
Comment 11 dfilter service freebsd_committer 2014-01-02 15:43:27 UTC
Author: ashish
Date: Thu Jan  2 15:43:18 2014
New Revision: 338450
URL: http://svnweb.freebsd.org/changeset/ports/338450

Log:
  - Add PKGNAMESUFFIX
  - Add STAGE support
  - Use OptionsNG helpers
  - Rename X11TOOLKIT option to X11
  - Add OPTIONS for emacs-nox11 slave
  - Install info manuals to their own directory to avoid conflicts[1][3][4]
  - Add a patch from upstream to fix building on non-X11 platforms[2]
  - Add a patch from upstream to fix building on 9.x and later platforms
    due to C11 support
  - Explicitly depend on GCC for i386 platforms, broken due to clang bug# 18171
  - Mark port as MAKE_JOBS_SAFE
  
  PR:		ports/183064[2], ports/181758[3], ports/179843[4]
  Reported by:	Jay Borkenhagen <jayb at braeburn.org>[1]

Added:
  head/editors/emacs/files/patch-c113322.diff   (contents, props changed)
  head/editors/emacs/files/patch-src_xdisp.c   (contents, props changed)
Modified:
  head/editors/emacs-nox11/Makefile
  head/editors/emacs/Makefile
  head/editors/emacs/files/patch-src_sysdep.c
  head/editors/emacs/pkg-plist

Modified: head/editors/emacs-nox11/Makefile
==============================================================================
--- head/editors/emacs-nox11/Makefile	Thu Jan  2 15:36:47 2014	(r338449)
+++ head/editors/emacs-nox11/Makefile	Thu Jan  2 15:43:18 2014	(r338450)
@@ -1,33 +1,17 @@
 # Created by: phoffman@proper.com
 # $FreeBSD$
 
-PORTREVISION=		8
 PKGNAMESUFFIX=	-nox11
 
-WITHOUT_CANNA=		yes
-WITHOUT_DBUS=		yes
-WITHOUT_GCONF=		yes
-WITHOUT_GTK2=		yes
-WITHOUT_JPEG=		yes
-WITHOUT_M17N=		yes
-WITHOUT_MOTIF=		yes
-WITHOUT_OTF=		yes
-WITHOUT_PNG=		yes
-WITHOUT_SVG=		yes
-WITHOUT_TIFF=		yes
-WITHOUT_XAW=		yes
-WITHOUT_XAW3D=		yes
-WITH_SYNC_INPUT=	yes
-WITHOUT_SCROLLBARS=	yes
-WITHOUT_X11=		yes
-WITHOUT_XFT=		yes
-WITHOUT_XIM=		yes
-WITHOUT_XPM=		yes
+PORTREVISION=	9
+
+OPTIONS_EXCLUDE=GCONF GIF JPEG OTF M17N PNG SVG TIFF SYNC_INPUT GTK2 GTK3 \
+		SCROLLBARS XFT XIM XPM MAGICK GSETTINGS X11 CANNA \
+		XAW XAW3D MOTIF
 
 EMACS_NO_X11_SLAVE=	yes
 
 MASTERDIR=	${.CURDIR}/../emacs
 LATEST_LINK=	emacs-nox11
 
-NO_STAGE=	yes
 .include "${MASTERDIR}/Makefile"

Modified: head/editors/emacs/Makefile
==============================================================================
--- head/editors/emacs/Makefile	Thu Jan  2 15:36:47 2014	(r338449)
+++ head/editors/emacs/Makefile	Thu Jan  2 15:43:18 2014	(r338450)
@@ -3,10 +3,15 @@
 
 PORTNAME=	emacs
 PORTVERSION=	${EMACS_VER}
+PORTREVISION?=	1
 PORTEPOCH=	3
 CATEGORIES=	editors ipv6
 MASTER_SITES=	${MASTER_SITE_GNU}
 MASTER_SITE_SUBDIR=	${PORTNAME}
+PKGNAMESUFFIX?=	24
+
+PATCH_SITE_SUBDIR+=	ashish
+PATCH_DIST_STRIP=	-p1
 
 MAINTAINER=	ashish@FreeBSD.org
 COMMENT=	GNU editing macros
@@ -14,6 +19,7 @@ COMMENT=	GNU editing macros
 LICENSE=	GPLv3
 LICENSE_FILE=	${WRKSRC}/COPYING
 
+MAKE_JOBS_SAFE=	yes
 
 CONFLICTS=	emacs-19.* emacs-21.* emacs-22.* emacs-23.* \
 		xemacs-[0-9]* xemacs-devel-[0-9]* \
@@ -25,13 +31,13 @@ USES=		ncurses gmake pkgconfig
 USE_XZ=		yes
 CPPFLAGS+=	-I${LOCALBASE}/include
 LDFLAGS+=	-L${LOCALBASE}/lib
-CONFIGURE_ARGS=	--localstatedir=/var
+INFO_PATH=	${DATADIR_REL}/info
+CONFIGURE_ARGS=	--localstatedir=/var --without-compress-info
 WRKSRC=		${WRKDIR}/${PORTNAME}-${PORTVERSION}
 
 MAN1=		ctags.1 ebrowse.1 emacs.1 emacsclient.1 etags.1 \
 		grep-changelog.1
-MANCOMPRESSED=	yes
-PLIST_SUB=	EMACS_VER=${EMACS_VER}
+PLIST_SUB=	EMACS_VER=${EMACS_VER} INFODIR=${INFO_PATH}
 
 EMACS_DIRS=	${DATADIR}/${EMACS_VER}/leim ${DATADIR}/${EMACS_VER}/lisp ${DATADIR}/${EMACS_VER}/src \
 		${PREFIX}/libexec/${PORTNAME}
@@ -45,12 +51,11 @@ INFO=		ada-mode auth autotype bovine cal
 		org pcl-cvs pgg rcirc reftex remember sasl sc semantic ses sieve \
 		smtpmail speedbar srecode tramp url vip viper widget wisent woman
 
-.if !defined(EMACS_NO_X11_SLAVE)
 CONFLICTS+=	emacs-nox11-[0-9]*
-OPTIONS_DEFINE=	CANNA DBUS GCONF GIF JPEG M17N OTF PNG SOUND SOURCES SVG TIFF SYNC_INPUT SCROLLBARS XFT \
+OPTIONS_DEFINE=	CANNA DBUS GCONF GIF JPEG M17N OTF PNG SOUND SOURCES SVG TIFF SYNC_INPUT SCROLLBARS X11 XFT \
 		XIM XML XPM MAGICK GNUTLS GSETTINGS
 
-OPTIONS_SINGLE=	X11TOOLKIT
+OPTIONS_SINGLE=	X11
 
 CANNA_DESC=		Canna support
 GSETTINGS_DESC=		GSettings support (requires DBUS)
@@ -64,183 +69,143 @@ XIM_DESC=		X Input Method Support
 M17N_DESC=		M17N support for text-shaping
 OTF_DESC=		Opentype fonts suport
 
-OPTIONS_SINGLE_X11TOOLKIT=	GTK2 GTK3 XAW XAW3D MOTIF
+OPTIONS_SINGLE_X11=	GTK2 GTK3 XAW XAW3D MOTIF
 
+.if !defined(EMACS_NO_X11_SLAVE)
 OPTIONS_DEFAULT=DBUS GCONF GIF GTK2 JPEG M17N OTF PNG SOUND SOURCES SVG TIFF SYNC_INPUT \
-		SCROLLBARS XFT XIM XML XPM MAGICK GNUTLS GSETTINGS
+		SCROLLBARS XFT XIM XML XPM MAGICK GNUTLS GSETTINGS X11
+.else
+OPTIONS_DEFAULT=SOURCES GNUTLS XML
 .endif
 
-NO_STAGE=	yes
-.include <bsd.port.options.mk>
-
-DBUS_PTHREAD_LIBS=	${CC} -dumpspecs | ${GREP} -m 1 pthread: | ${SED} -e 's|^.*%{\!pg: %{pthread:||' -e 's|}.*$$||' || ${TRUE}
+OPTIONS_SUB=		SOURCES
 
-.if ${PORT_OPTIONS:MCANNA}
-PATCH_SITES+=	http://distfiles.pirateparty.in/%SUBDIR%/ ${MASTER_SITE_LOCAL}
-PATCH_SITE_SUBDIR+=	ashish
-PATCHFILES+=	emacs24.3canna-20130321.diff.gz
-PATCH_DIST_STRIP=	-p1
-CONFIGURE_ARGS+=	--with-canna \
+CANNA_CONFIGURE_ON=	--with-canna \
 			--with-canna-includes=${LOCALBASE}/include \
 			--with-canna-libraries=${LOCALBASE}/lib
-LIB_DEPENDS+=		canna:${PORTSDIR}/japanese/canna-lib
-.endif
+CANNA_PATCH_SITES=	http://distfiles.pirateparty.in/%SUBDIR%/ ${MASTER_SITE_LOCAL}
+CANNA_PATCHFILES=	emacs24.3canna-20130321.diff.gz
+CANNA_LIB_DEPENDS=	canna:${PORTSDIR}/japanese/canna-lib
 
-.if defined(WITHOUT_X11)
-CONFIGURE_ARGS+=	--without-x
-.else
-USE_XORG=	x11
-USE_GNOME=
-INSTALLS_ICONS=	yes
+SOUND_CONFIGURE_WITH=		sound
 
-.if ${PORT_OPTIONS:MSVG}
-USE_GNOME+=	librsvg2
-.else
-CONFIGURE_ARGS+=	--without-rsvg
-.endif
+DBUS_LIB_DEPENDS=		dbus-1:${PORTSDIR}/devel/dbus
+DBUS_CONFIGURE_WITH=		dbus
 
-.if ${PORT_OPTIONS:MGTK2}
-USE_GNOME+=	gtk20
-CONFIGURE_ARGS+=	--with-x-toolkit=gtk2
-.elif ${PORT_OPTIONS:MGTK3}
-USE_GNOME+=	gtk30
-CONFIGURE_ARGS+=	--with-x-toolkit=gtk3
-.elif ${PORT_OPTIONS:MXAW3D}
-LIB_DEPENDS+=	Xaw3d:${PORTSDIR}/x11-toolkits/Xaw3d
-CONFIGURE_ARGS+=	--with-x-toolkit=athena
-.elif ${PORT_OPTIONS:MXAW}
-USE_XORG=	xaw
-CONFIGURE_ARGS+=	--with-x-toolkit=athena --without-xaw3d
-.elif ${PORT_OPTIONS:MMOTIF}
-USES+=		motif
-CONFIGURE_ARGS+=	--with-x-toolkit=motif
-.endif
+GNUTLS_LIB_DEPENDS=	gnutls:${PORTSDIR}/security/gnutls
+GNUTLS_CONFIGURE_WITH=	gnutls
 
-.if !${PORT_OPTIONS:MSCROLLBARS}
-CONFIGURE_ARGS+=	--without-toolkit-scroll-bars
-.endif
+XML_USE=		GNOME=libxml2
+XML_CONFIGURE_WITH=	xml2
 
-.if !${PORT_OPTIONS:MSYNC_INPUT}
-CONFIGURE_ARGS+=	--without-sync-input
-.endif
+SVG_USE=	GNOME=librsvg2
+SVG_CONFIGURE_WITH=	rsvg
 
-.if ${PORT_OPTIONS:MJPEG}
-LIB_DEPENDS+=	jpeg:${PORTSDIR}/graphics/jpeg
-.else
-CONFIGURE_ARGS+=	--without-jpeg
-.endif
+GTK2_USE=	GNOME=gtk20
+GTK2_CONFIGURE_ON=	--with-x-toolkit=gtk2
 
-.if ${PORT_OPTIONS:MTIFF}
-LIB_DEPENDS+=	tiff:${PORTSDIR}/graphics/tiff
-.else
-CONFIGURE_ARGS+=	--without-tiff
-.endif
+GTK3_USE=	GNOME=gtk30
+GTK3_CONFIGURE_ON=	--with-x-toolkit=gtk3
 
-.if ${PORT_OPTIONS:MGIF}
-LIB_DEPENDS+=   gif:${PORTSDIR}/graphics/giflib
-.else
-CONFIGURE_ARGS+=	--without-gif
-.endif
+XAW3D_LIB_DEPENDS=	Xaw3d:${PORTSDIR}/x11-toolkits/Xaw3d
+XAW3D_CONFIGURE_ON=	--with-x-toolkit=athena
 
-.if ${PORT_OPTIONS:MPNG}
-LIB_DEPENDS+=	png15:${PORTSDIR}/graphics/png
-.else
-CONFIGURE_ARGS+=	--without-png
-.endif
+XAW_USE=	XORG=xaw
+XAW_CONFIGURE_ON+=	--with-x-toolkit=athena --without-xaw3d
 
-.if ${PORT_OPTIONS:MXPM}
-USE_XORG+=	xpm
-.else
-CONFIGURE_ARGS+=	--without-xpm
-.endif
+MOTIF_USES=	motif
+MOTIF_CONFIGURE_ON+=	--with-x-toolkit=motif
 
-.if ${PORT_OPTIONS:MXFT}
-USE_XORG+=	xft
-LIB_DEPENDS+=	freetype:${PORTSDIR}/print/freetype2
-CONFIGURE_ARGS+=	--with-xft
-.if ${PORT_OPTIONS:MM17N}
-CONFIGURE_ARGS+=	--with-m17n-flt
-LIB_DEPENDS+=	m17n:${PORTSDIR}/devel/m17n-lib
-.else
-CONFIGURE_ARGS+=	--without-m17n-flt
-.endif
-.if ${PORT_OPTIONS:MOTF}
-CONFIGURE_ARGS+=	--with-otf
-LIB_DEPENDS+=	otf:${PORTSDIR}/print/libotf
-.else
-CONFIGURE_ARGS+=	--without-libotf
+SCROLLBARS_CONFIGURE_WITH=	toolkit-scroll-bars
+
+SYNC_INPUT_CONFIGURE_WITH=	sync-input
+
+JPEG_LIB_DEPENDS=	jpeg:${PORTSDIR}/graphics/jpeg
+JPEG_CONFIGURE_WITH=	jpeg
+
+TIFF_LIB_DEPENDS=	tiff:${PORTSDIR}/graphics/tiff
+TIFF_CONFIGURE_WITH=	tiff
+
+GIF_LIB_DEPENDS=	gif:${PORTSDIR}/graphics/giflib
+GIF_CONFIGURE_WITH=	gif
+
+PNG_LIB_DEPENDS+=	png15:${PORTSDIR}/graphics/png
+PNG_CONFIGURE_WITH=	png
+
+XPM_USE=		XORG=xpm
+XPM_CONFIGURE_WITH=	xpm
+
+XFT_USE=		XORG=xft
+XFT_LIB_DEPENDS=	freetype:${PORTSDIR}/print/freetype2
+XFT_CONFIGURE_WITH=	xft
+
+M17N_LIB_DEPENDS=	m17n:${PORTSDIR}/devel/m17n-lib
+M17N_CONFIGURE_WITH=	m17n-flt
+
+OTF_LIB_DEPENDS=	otf:${PORTSDIR}/print/libotf
+OTF_CONFIGURE_WITH=	libotf
+
+MAGICK_LIB_DEPENDS=	MagickCore:${PORTSDIR}/graphics/ImageMagick
+MAGICK_CONFIGURE_WITH=	imagemagick
+
+GSETTINGS_USE=			gnome=glib20
+GSETTINGS_CONFIGURE_WITH=	gsettings
+
+GCONF_USE=			gnome=gconf2
+GCONF_CONFIGURE_WITH=		gconf
+
+XIM_CONFIGURE_WITH=		xim
+
+.include <bsd.port.options.mk>
+
+# clang is broken on i386 platform in -O2, due to use of alloca
+# and %esi as frame pointer register
+.if ${ARCH} == "i386"
+USE_GCC=			any
 .endif
-.else
-CONFIGURE_ARGS+=	--without-xft
+
+DBUS_PTHREAD_LIBS=	${CC} -dumpspecs | ${GREP} -m 1 pthread: | ${SED} -e 's|^.*%{\!pg: %{pthread:||' -e 's|}.*$$||' || ${TRUE}
+
+.if ${PORT_OPTIONS:MX11}
+
+CONFIGURE_ARGS+=	--with-x
+USE_XORG=		x11
+
+INSTALLS_ICONS=	yes
+
+.if !${PORT_OPTIONS:MXFT}
 .if ${PORT_OPTIONS:MM17N}
 IGNORE=	m17n support for text-shaping requires Xft. Please run 'make config'
 .elif ${PORT_OPTIONS:MOTF}
 IGNORE=	opentype fonts support requires Xft. Please run 'make config'
 .endif
-CONFIGURE_ARGS+=	--without-otf --without-m17n-flt
 .endif
 
-.if ${PORT_OPTIONS:MMAGICK}
-LIB_DEPENDS+=		MagickCore:${PORTSDIR}/graphics/ImageMagick
-CONFIGURE_ARGS+=	--with-imagemagick
 .else
-CONFIGURE_ARGS+=	--without-imagemagick
-.endif
 
-.if ${PORT_OPTIONS:MGSETTINGS}
-USE_GNOME+=	glib20
-CONFIGURE_ARGS+=	--with-gsettings
-.else
-CONFIGURE_ARGS+=	--without-gsettings
-.endif
-
-.if ${PORT_OPTIONS:MGCONF}
-USE_GNOME+=	gconf2
-CONFIGURE_ARGS+=	--with-gconf
-.else
-CONFIGURE_ARGS+=	--without-gconf
-.endif
-
-.if ${PORT_OPTIONS:MXIM}
-CONFIGURE_ARGS+=	--with-xim
-.else
-CONFIGURE_ARGS+=	--without-xim
-.endif
+CONFIGURE_ARGS+=	--without-x
 
+.for OPT in SVG GTK2 GTK3 XAW3D XAW MOTIF SCROLLBARS JPEG TIFF GIF PNG XPM XFT M17N MAGICK GCONF GSETTINGS XIM
+.if ${PORT_OPTIONS:M${OPT}}
+IGNORE=	${OPT} option depends on X11 option
 .endif
+.endfor
 
-.if ${PORT_OPTIONS:MSOUND}
-CONFIGURE_ARGS+=	--with-sound
-.else
-CONFIGURE_ARGS+=	--without-sound
 .endif
 
-.if ${PORT_OPTIONS:MDBUS}
-LIB_DEPENDS+=	dbus-1:${PORTSDIR}/devel/dbus
-CONFIGURE_ARGS+=	--with-dbus
-.else
-CONFIGURE_ARGS+=	--without-dbus
+.if !${PORT_OPTIONS:MDBUS}
 .if ${PORT_OPTIONS:MGSETTINGS}
 IGNORE=	GSettings support requires DBUS. Please run 'make config'
 .endif
 .endif
 
-.if ${PORT_OPTIONS:MXML}
-USE_GNOME+=		libxml2
-CONFIGURE_ARGS+=	--with-xml2
-.else
-CONFIGURE_ARGS+=	--without-xml2
-.endif
+.include <bsd.port.pre.mk>
 
-.if ${PORT_OPTIONS:MGNUTLS}
-LIB_DEPENDS+=		gnutls:${PORTSDIR}/security/gnutls
-CONFIGURE_ARGS+=	--with-gnutls
-.else
-CONFIGURE_ARGS+=	--without-gnutls
+# Building with GCC 4.6+ requires it
+.if ${ncurses_ARGS} == "port"
+LDFLAGS+=	-ltinfo
 .endif
 
-.include <bsd.port.pre.mk>
-
 .if ${ARCH} == "ia64"
 BROKEN=	Emacs 24.X does not currently build on ia64
 .endif
@@ -248,7 +213,7 @@ BROKEN=	Emacs 24.X does not currently bu
 post-patch:
 	@${RM} -f ${WRKSRC}/info/*
 	@${REINPLACE_CMD} -e "s/%%EMACS_VER%%/${EMACS_VER}/g" -e "s/%%DATADIR%%/${DATADIR:C/\//\\\//g}/g" ${WRKSRC}/sources.el
-.if defined(WITHOUT_X11)
+.if ${PORT_OPTIONS:MX11}
 	@${REINPLACE_CMD} -e 's/^Terminal=.*$$/Terminal=true/' ${WRKSRC}/etc/emacs.desktop
 .endif
 
@@ -257,33 +222,29 @@ post-configure:
 
 add-plist-data:
 .for i in ${EMACS_DIRS}
-	@${FIND} ${i} -type f |${SED} -E -e 's,^${PREFIX}/,,g'  >>${TMPPLIST}
+	@${FIND} ${STAGEDIR}${i} -type f |${SED} -E -e 's,^${STAGEDIR}${PREFIX}/,,g'  >>${TMPPLIST}
 .endfor
 	@${FIND} ${WRKSRC}/etc -type f |${SED} -E -e 's,^${WRKSRC},${DATADIR_REL}/${EMACS_VER},g' -e '/etc\/(\..*|ChangeLog|DOC)$$/d' >>${TMPPLIST}
 	@${FIND} ${WRKSRC}/etc -type d -depth |${SED} -E -e 's,^${WRKSRC},@dirrm ${DATADIR_REL}/${EMACS_VER},g' >>${TMPPLIST}
 .for i in ${EMACS_DIRS}
-	@${FIND} ${i} -type d -depth |${SED} -E -e 's,^${PREFIX}/,@dirrm ,g' >>${TMPPLIST}
+	@${FIND} ${STAGEDIR}${i} -type d -depth |${SED} -E -e 's,^${STAGEDIR}${PREFIX}/,@dirrm ,g' >>${TMPPLIST}
 .endfor
 	@${ECHO} "@unexec rmdir %D/${DATADIR_REL}/${EMACS_VER} 2>/dev/null || true" >>${TMPPLIST}
 
-.if defined(WITH_SOURCES)
-PLIST_SUB+=	SOURCES=""
-
+.if ${PORT_OPTIONS:MSOURCES}
 post-install:
-	@${MKDIR} ${DATADIR}/${EMACS_VER}/src
-	@${INSTALL_DATA} ${WRKSRC}/src/*.[ch] ${DATADIR}/${EMACS_VER}/src
-	@${INSTALL_DATA} ${WRKSRC}/sources.el ${DATADIR}/${EMACS_VER}/site-lisp/site-start.el
-.else
-PLIST_SUB+=	SOURCES="@comment "
+	@${MKDIR} ${STAGEDIR}${DATADIR}/${EMACS_VER}/src
+	@${INSTALL_DATA} ${WRKSRC}/src/*.[ch] ${STAGEDIR}${DATADIR}/${EMACS_VER}/src
+	@${INSTALL_DATA} ${WRKSRC}/sources.el ${STAGEDIR}${DATADIR}/${EMACS_VER}/site-lisp/site-start.el
 .endif
 
 pre-everything::
-.if !defined(WITHOUT_X11)
+.if ${PORT_OPTIONS:MX11}
 	@${ECHO_MSG}
-	@${ECHO_MSG} "====> To disable X11 support, define: WITHOUT_X11."
+	@${ECHO_MSG} "====> To disable X11 support, unset option: X11."
 	@${ECHO_MSG}
 .endif
-.if defined(WITH_CANNA)
+.if ${PORT_OPTIONS:MCANNA}
 	@${ECHO_MSG} "====> Canna support is not part of standard distribution"
 	@${ECHO_MSG} "====> of GNU Emacs and is therefore not supported by GNU"
 	@${ECHO_MSG} "====> Emacs development team."

Added: head/editors/emacs/files/patch-c113322.diff
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/editors/emacs/files/patch-c113322.diff	Thu Jan  2 15:43:18 2014	(r338450)
@@ -0,0 +1,276 @@
+
+$FreeBSD$
+
+Backport of changeset: 113322
+fixes bug: http://debbugs.gnu.org/14812
+committer: Paul Eggert <eggert@cs.ucla.edu>
+branch nick: trunk
+timestamp: Sun 2013-07-07 23:15:38 -0700
+message:
+  Try to fix FreeBSD 9.1 porting problem.
+  
+  This incorporates the following merge from gnulib:
+  2013-07-07 stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
+
+--- lib/verify.h.orig
++++ lib/verify.h
+@@ -18,7 +18,7 @@
+ /* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
+ 
+ #ifndef _GL_VERIFY_H
+-# define _GL_VERIFY_H
++#define _GL_VERIFY_H
+ 
+ 
+ /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11.
+@@ -31,14 +31,24 @@
+    Use this only with GCC.  If we were willing to slow 'configure'
+    down we could also use it with other compilers, but since this
+    affects only the quality of diagnostics, why bother?  */
+-# if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined __cplusplus
+-#  define _GL_HAVE__STATIC_ASSERT 1
+-# endif
++#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
++      && (201112L <= __STDC_VERSION__  || !defined __STRICT_ANSI__) \
++      && !defined __cplusplus)
++# define _GL_HAVE__STATIC_ASSERT 1
++#endif
+ /* The condition (99 < __GNUC__) is temporary, until we know about the
+    first G++ release that supports static_assert.  */
+-# if (99 < __GNUC__) && defined __cplusplus
+-#  define _GL_HAVE_STATIC_ASSERT 1
+-# endif
++#if (99 < __GNUC__) && defined __cplusplus
++# define _GL_HAVE_STATIC_ASSERT 1
++#endif
++
++/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
++   system headers, defines a conflicting _Static_assert that is no
++   better than ours; override it.  */
++#ifndef _GL_HAVE_STATIC_ASSERT
++# include <stddef.h>
++# undef _Static_assert
++#endif
+ 
+ /* Each of these macros verifies that its argument R is nonzero.  To
+    be portable, R should be an integer constant expression.  Unlike
+@@ -141,50 +151,50 @@
+      Use a template type to work around the problem.  */
+ 
+ /* Concatenate two preprocessor tokens.  */
+-# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
+-# define _GL_CONCAT0(x, y) x##y
++#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
++#define _GL_CONCAT0(x, y) x##y
+ 
+ /* _GL_COUNTER is an integer, preferably one that changes each time we
+    use it.  Use __COUNTER__ if it works, falling back on __LINE__
+    otherwise.  __LINE__ isn't perfect, but it's better than a
+    constant.  */
+-# if defined __COUNTER__ && __COUNTER__ != __COUNTER__
+-#  define _GL_COUNTER __COUNTER__
+-# else
+-#  define _GL_COUNTER __LINE__
+-# endif
++#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
++# define _GL_COUNTER __COUNTER__
++#else
++# define _GL_COUNTER __LINE__
++#endif
+ 
+ /* Generate a symbol with the given prefix, making it unique if
+    possible.  */
+-# define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
++#define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
+ 
+ /* Verify requirement R at compile-time, as an integer constant expression
+    that returns 1.  If R is false, fail at compile-time, preferably
+    with a diagnostic that includes the string-literal DIAGNOSTIC.  */
+ 
+-# define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
+-    (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
++#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
++   (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
+ 
+-# ifdef __cplusplus
+-#  if !GNULIB_defined_struct__gl_verify_type
++#ifdef __cplusplus
++# if !GNULIB_defined_struct__gl_verify_type
+ template <int w>
+   struct _gl_verify_type {
+     unsigned int _gl_verify_error_if_negative: w;
+   };
+-#   define GNULIB_defined_struct__gl_verify_type 1
+-#  endif
+-#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+-    _gl_verify_type<(R) ? 1 : -1>
+-# elif defined _GL_HAVE__STATIC_ASSERT
+-#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+-     struct {                                   \
+-       _Static_assert (R, DIAGNOSTIC);          \
+-       int _gl_dummy;                          \
+-     }
+-# else
+-#  define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+-     struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
++#  define GNULIB_defined_struct__gl_verify_type 1
+ # endif
++# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
++    _gl_verify_type<(R) ? 1 : -1>
++#elif defined _GL_HAVE__STATIC_ASSERT
++# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
++    struct {                                   \
++      _Static_assert (R, DIAGNOSTIC);          \
++      int _gl_dummy;                          \
++    }
++#else
++# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
++    struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
++#endif
+ 
+ /* Verify requirement R at compile-time, as a declaration without a
+    trailing ';'.  If R is false, fail at compile-time, preferably
+@@ -193,23 +203,23 @@
+    Unfortunately, unlike C11, this implementation must appear as an
+    ordinary declaration, and cannot appear inside struct { ... }.  */
+ 
+-# ifdef _GL_HAVE__STATIC_ASSERT
+-#  define _GL_VERIFY _Static_assert
+-# else
+-#  define _GL_VERIFY(R, DIAGNOSTIC)				       \
+-     extern int (*_GL_GENSYM (_gl_verify_function) (void))	       \
+-       [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
+-# endif
++#ifdef _GL_HAVE__STATIC_ASSERT
++# define _GL_VERIFY _Static_assert
++#else
++# define _GL_VERIFY(R, DIAGNOSTIC)				       \
++    extern int (*_GL_GENSYM (_gl_verify_function) (void))	       \
++      [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
++#endif
+ 
+ /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
+-# ifdef _GL_STATIC_ASSERT_H
+-#  if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
+-#   define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
+-#  endif
+-#  if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
+-#   define static_assert _Static_assert /* C11 requires this #define.  */
+-#  endif
++#ifdef _GL_STATIC_ASSERT_H
++# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
++#  define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
++# endif
++# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
++#  define static_assert _Static_assert /* C11 requires this #define.  */
+ # endif
++#endif
+ 
+ /* @assert.h omit start@  */
+ 
+@@ -227,18 +237,18 @@
+ 
+    verify_true is obsolescent; please use verify_expr instead.  */
+ 
+-# define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
++#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
+ 
+ /* Verify requirement R at compile-time.  Return the value of the
+    expression E.  */
+ 
+-# define verify_expr(R, E) \
+-    (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
++#define verify_expr(R, E) \
++   (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
+ 
+ /* Verify requirement R at compile-time, as a declaration without a
+    trailing ';'.  */
+ 
+-# define verify(R) _GL_VERIFY (R, "verify (" #R ")")
++#define verify(R) _GL_VERIFY (R, "verify (" #R ")")
+ 
+ /* @assert.h omit end@  */
+ 
+
+--- lib/stdalign.in.h.orig
++++ lib/stdalign.in.h
+@@ -41,13 +41,28 @@
+    are 4 unless the option '-malign-double' is used.
+ 
+    The result cannot be used as a value for an 'enum' constant, if you
+-   want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
++   want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc.
++
++   Include <stddef.h> for offsetof.  */
+ #include <stddef.h>
+-#if defined __cplusplus
++
++/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
++   standard headers, defines conflicting implementations of _Alignas
++   and _Alignof that are no better than ours; override them.  */
++#undef _Alignas
++#undef _Alignof
++
++#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
++# ifdef __cplusplus
++#  if 201103 <= __cplusplus
++#   define _Alignof(type) alignof (type)
++#  else
+    template <class __t> struct __alignof_helper { char __a; __t __b; };
+-# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+-#else
+-# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
++#   define _Alignof(type) offsetof (__alignof_helper<type>, __b)
++#  endif
++# else
++#  define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
++# endif
+ #endif
+ #define alignof _Alignof
+ #define __alignof_is_defined 1
+@@ -77,12 +92,16 @@
+ 
+    */
+ 
+-#if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C
+-# define _Alignas(a) __attribute__ ((__aligned__ (a)))
+-#elif 1300 <= _MSC_VER
+-# define _Alignas(a) __declspec (align (a))
++#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
++# if defined __cplusplus && 201103 <= __cplusplus
++#  define _Alignas(a) alignas (a)
++# elif __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC || 0x5110 <= __SUNPRO_C
++#  define _Alignas(a) __attribute__ ((__aligned__ (a)))
++# elif 1300 <= _MSC_VER
++#  define _Alignas(a) __declspec (align (a))
++# endif
+ #endif
+-#ifdef _Alignas
++#if defined _Alignas || (defined __STDC_VERSION && 201112 <= __STDC_VERSION__)
+ # define alignas _Alignas
+ # define __alignas_is_defined 1
+ #endif
+--- m4/stdalign.m4.orig
++++ m4/stdalign.m4
+@@ -31,7 +31,8 @@
+ 
+             /* Test _Alignas only on platforms where gnulib can help.  */
+             #if \
+-                (__GNUC__ || __IBMC__ || __IBMCPP__ \
++                ((defined __cplusplus && 201103 <= __cplusplus) \
++                 || __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC \
+                  || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER)
+               int alignas (8) alignas_int = 1;
+               char test_alignas[_Alignof (alignas_int) == 8 ? 1 : -1];
+--- ChangeLog.orig
++++ ChangeLog
+@@ -1,3 +1,9 @@
++2013-07-08  Paul Eggert  <eggert@cs.ucla.edu>
++
++	Try to fix FreeBSD 9.1 porting problem (Bug#14812).
++	This incorporates the following merge from gnulib:
++	2013-07-07 stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
++
+ 2013-03-11  Glenn Morris  <rgm@gnu.org>
+ 
+ 	* Verson 24.3 released.

Modified: head/editors/emacs/files/patch-src_sysdep.c
==============================================================================
--- head/editors/emacs/files/patch-src_sysdep.c	Thu Jan  2 15:36:47 2014	(r338449)
+++ head/editors/emacs/files/patch-src_sysdep.c	Thu Jan  2 15:43:18 2014	(r338450)
@@ -3,24 +3,29 @@ $FreeBSD$
 
 --- src/sysdep.c.orig
 +++ src/sysdep.c
-@@ -46,7 +46,15 @@
- #endif
+@@ -37,6 +37,20 @@
+ #include "sysselect.h"
+ #include "blockinput.h"
  
- #ifdef __FreeBSD__
++#ifdef __FreeBSD__
 +#include <sys/sysctl.h>
 +/* machine/frame.h in Sparc/ARM has 'struct frame' which conflicts with Emacs' 'struct frame', so rename it */
 +#if defined(__sparc__) || defined(__arm__)
 +#define frame freebsd_sparc_frame
 +#endif
- #include <sys/user.h>
++#include <sys/user.h>
 +#if defined(__sparc__) || defined(__arm__)
 +#undef frame
 +#endif
- #include <sys/resource.h>
- #include <math.h>
- #endif
-@@ -2691,6 +2699,40 @@
-   return  proclist;
++#include <sys/resource.h>
++#include <math.h>
++#endif
++
+ #ifdef WINDOWSNT
+ #define read sys_read
+ #define write sys_write
+@@ -2529,6 +2543,40 @@
+   return proclist;
  }
  
 +#elif defined (__FreeBSD__)
@@ -60,7 +65,7 @@ $FreeBSD$
  /* The WINDOWSNT implementation is in w32.c.
     The MSDOS implementation is in dosfns.c.  */
  #elif !defined (WINDOWSNT) && !defined (MSDOS)
-@@ -3402,6 +3444,176 @@
+@@ -3079,6 +3127,176 @@
    return attrs;
  }
  

Added: head/editors/emacs/files/patch-src_xdisp.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/editors/emacs/files/patch-src_xdisp.c	Thu Jan  2 15:43:18 2014	(r338450)
@@ -0,0 +1,23 @@
+This patch is taken from upstream repository r114482.
+
+
+$FreeBSD$
+
+--- src/xdisp.c.orig
++++ src/xdisp.c
+@@ -6870,6 +6870,7 @@
+ 	}
+     }
+ 
++#ifdef HAVE_WINDOW_SYSTEM
+   /* Adjust face id for a multibyte character.  There are no multibyte
+      character in unibyte text.  */
+   if ((it->what == IT_CHARACTER || it->what == IT_COMPOSITION)
+@@ -6910,6 +6911,7 @@
+ 	  it->face_id = FACE_FOR_CHAR (it->f, face, c, pos, it->string);
+ 	}
+     }
++#endif	/* HAVE_WINDOW_SYSTEM */
+ 
+  done:
+   /* Is this character the last one of a run of characters with

Modified: head/editors/emacs/pkg-plist
==============================================================================
--- head/editors/emacs/pkg-plist	Thu Jan  2 15:36:47 2014	(r338449)
+++ head/editors/emacs/pkg-plist	Thu Jan  2 15:43:18 2014	(r338450)
@@ -5,10 +5,17 @@ bin/emacs-%%EMACS_VER%%
 bin/emacsclient
 bin/etags
 bin/grep-changelog
+man/man1/grep-changelog.1.gz
+man/man1/etags.1.gz
+man/man1/ctags.1.gz
+man/man1/ebrowse.1.gz
+man/man1/emacsclient.1.gz
+man/man1/emacs.1.gz
 share/applications/emacs.desktop
 %%SOURCES%%%%DATADIR%%/%%EMACS_VER%%/site-lisp/site-start.el
 %%DATADIR%%/%%EMACS_VER%%/site-lisp/subdirs.el
 %%DATADIR%%/site-lisp/subdirs.el
+%%INFODIR%%/dir
 share/icons/hicolor/128x128/apps/emacs.png
 share/icons/hicolor/16x16/apps/emacs.png
 share/icons/hicolor/24x24/apps/emacs.png
@@ -16,6 +23,7 @@ share/icons/hicolor/32x32/apps/emacs.png
 share/icons/hicolor/48x48/apps/emacs.png
 share/icons/hicolor/scalable/apps/emacs.svg
 share/icons/hicolor/scalable/mimetypes/emacs-document.svg
+@dirrmtry %%INFODIR%%
 @dirrmtry %%DATADIR%%/%%EMACS_VER%%/site-lisp
 @dirrmtry share/icons/hicolor/scalable/mimetypes
 @dirrmtry share/icons/hicolor/scalable/apps
_______________________________________________
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"
Comment 12 Ashish SHUKLA freebsd_committer 2014-01-04 20:14:26 UTC
State Changed
From-To: open->closed

Committed. Thanks!
Comment 13 dfilter service freebsd_committer 2014-03-18 19:23:47 UTC
Author: dim
Date: Tue Mar 18 19:23:41 2014
New Revision: 263312
URL: http://svnweb.freebsd.org/changeset/base/263312

Log:
  Pull in r196939 from upstream llvm trunk (by Reid Kleckner):
  
    Reland "Fix miscompile of MS inline assembly with stack realignment"
  
    This re-lands commit r196876, which was reverted in r196879.
  
    The tests have been fixed to pass on platforms with a stack alignment
    larger than 4.
  
    Update to clang side tests will land shortly.
  
  Pull in r196986 from upstream llvm trunk (by Reid Kleckner):
  
    Revert the backend fatal error from r196939
  
    The combination of inline asm, stack realignment, and dynamic allocas
    turns out to be too common to reject out of hand.
  
    ASan inserts empy inline asm fragments and uses aligned allocas.
    Compiling any trivial function containing a dynamic alloca with ASan is
    enough to trigger the check.
  
    XFAIL the test cases that would be miscompiled and add one that uses the
    relevant functionality.
  
  Pull in r202930 from upstream llvm trunk (by Hans Wennborg):
  
    Check for dynamic allocas and inline asm that clobbers sp before building
    selection dag (PR19012)
  
    In X86SelectionDagInfo::EmitTargetCodeForMemcpy we check with MachineFrameInfo
    to make sure that ESI isn't used as a base pointer register before we choose to
    emit rep movs (which clobbers esi).
  
    The problem is that MachineFrameInfo wouldn't know about dynamic allocas or
    inline asm that clobbers the stack pointer until SelectionDAGBuilder has
    encountered them.
  
    This patch fixes the problem by checking for such things when building the
    FunctionLoweringInfo.
  
    Differential Revision: http://llvm-reviews.chandlerc.com/D2954
  
  Together, these commits fix the problem encountered in the devel/emacs
  port on the i386 architecture, where a combination of stack realignment,
  alloca() and memcpy() could incidentally clobber the %esi register,
  leading to segfaults in the temacs build-time utility.
  
  See also: http://llvm.org/PR18171 and http://llvm.org/PR19012
  
  Reported by:	ashish
  PR:		ports/183064
  MFC after:	1 week

Modified:
  head/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
  head/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
  head/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
  head/contrib/llvm/lib/CodeGen/MachineFunction.cpp
  head/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  head/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
  head/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
  head/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp

Modified: head/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
==============================================================================
--- head/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Tue Mar 18 19:23:41 2014	(r263312)
@@ -41,6 +41,7 @@ class MachineBasicBlock;
 class MachineFunction;
 class MachineModuleInfo;
 class MachineRegisterInfo;
+class SelectionDAG;
 class TargetLowering;
 class Value;
 
@@ -125,7 +126,7 @@ public:
   /// set - Initialize this FunctionLoweringInfo with the given Function
   /// and its associated MachineFunction.
   ///
-  void set(const Function &Fn, MachineFunction &MF);
+  void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG);
 
   /// clear - Clear out all the function-specific state. This returns this
   /// FunctionLoweringInfo to an empty state, ready to be used for a

Modified: head/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
==============================================================================
--- head/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Tue Mar 18 19:23:41 2014	(r263312)
@@ -223,6 +223,10 @@ class MachineFrameInfo {
   /// Whether the "realign-stack" option is on.
   bool RealignOption;
 
+  /// True if the function includes inline assembly that adjusts the stack
+  /// pointer.
+  bool HasInlineAsmWithSPAdjust;
+
   const TargetFrameLowering *getFrameLowering() const;
 public:
     explicit MachineFrameInfo(const TargetMachine &TM, bool RealignOpt)
@@ -240,6 +244,7 @@ public:
     LocalFrameSize = 0;
     LocalFrameMaxAlign = 0;
     UseLocalStackAllocationBlock = false;
+    HasInlineAsmWithSPAdjust = false;
   }
 
   /// hasStackObjects - Return true if there are any stack objects in this
@@ -451,6 +456,10 @@ public:
   bool hasCalls() const { return HasCalls; }
   void setHasCalls(bool V) { HasCalls = V; }
 
+  /// Returns true if the function contains any stack-adjusting inline assembly.
+  bool hasInlineAsmWithSPAdjust() const { return HasInlineAsmWithSPAdjust; }
+  void setHasInlineAsmWithSPAdjust(bool B) { HasInlineAsmWithSPAdjust = B; }
+
   /// getMaxCallFrameSize - Return the maximum size of a call frame that must be
   /// allocated for an outgoing function call.  This is only available if
   /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
@@ -521,7 +530,7 @@ public:
   /// variable sized object is created, whether or not the index returned is
   /// actually used.
   ///
-  int CreateVariableSizedObject(unsigned Alignment);
+  int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
 
   /// getCalleeSavedInfo - Returns a reference to call saved info vector for the
   /// current function.

Modified: head/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
==============================================================================
--- head/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Tue Mar 18 19:23:41 2014	(r263312)
@@ -131,8 +131,8 @@ class MachineFunction {
   /// about the control flow of such functions.
   bool ExposesReturnsTwice;
 
-  /// True if the function includes MS-style inline assembly.
-  bool HasMSInlineAsm;
+  /// True if the function includes any inline assembly.
+  bool HasInlineAsm;
 
   MachineFunction(const MachineFunction &) LLVM_DELETED_FUNCTION;
   void operator=(const MachineFunction&) LLVM_DELETED_FUNCTION;
@@ -218,15 +218,14 @@ public:
     ExposesReturnsTwice = B;
   }
 
-  /// Returns true if the function contains any MS-style inline assembly.
-  bool hasMSInlineAsm() const {
-    return HasMSInlineAsm;
+  /// Returns true if the function contains any inline assembly.
+  bool hasInlineAsm() const {
+    return HasInlineAsm;
   }
 
-  /// Set a flag that indicates that the function contains MS-style inline
-  /// assembly.
-  void setHasMSInlineAsm(bool B) {
-    HasMSInlineAsm = B;
+  /// Set a flag that indicates that the function contains inline assembly.
+  void setHasInlineAsm(bool B) {
+    HasInlineAsm = B;
   }
   
   /// getInfo - Keep track of various per-function pieces of information for

Modified: head/contrib/llvm/lib/CodeGen/MachineFunction.cpp
==============================================================================
--- head/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -525,13 +525,14 @@ int MachineFrameInfo::CreateSpillStackOb
 /// variable sized object is created, whether or not the index returned is
 /// actually used.
 ///
-int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment) {
+int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment,
+                                                const AllocaInst *Alloca) {
   HasVarSizedObjects = true;
   Alignment =
     clampStackAlignment(!getFrameLowering()->isStackRealignable() ||
                           !RealignOption,
                         Alignment, getFrameLowering()->getStackAlignment()); 
-  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, 0));
+  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, Alloca));
   ensureMaxAlignment(Alignment);
   return (int)Objects.size()-NumFixedObjects-1;
 }

Modified: head/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
==============================================================================
--- head/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -33,6 +33,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetFrameLowering.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -55,7 +56,8 @@ static bool isUsedOutsideOfDefiningBlock
   return false;
 }
 
-void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
+void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
+                               SelectionDAG *DAG) {
   const TargetLowering *TLI = TM.getTargetLowering();
 
   Fn = &fn;
@@ -100,6 +102,43 @@ void FunctionLoweringInfo::set(const Fun
   for (; BB != EB; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
+      // Look for dynamic allocas.
+      if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
+        if (!AI->isStaticAlloca()) {
+          unsigned Align = std::max(
+              (unsigned)TLI->getDataLayout()->getPrefTypeAlignment(
+                AI->getAllocatedType()),
+              AI->getAlignment());
+          unsigned StackAlign = TM.getFrameLowering()->getStackAlignment();
+          if (Align <= StackAlign)
+            Align = 0;
+          // Inform the Frame Information that we have variable-sized objects.
+          MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, AI);
+        }
+      }
+
+      // Look for inline asm that clobbers the SP register.
+      if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
+        ImmutableCallSite CS(I);
+        if (const InlineAsm *IA = dyn_cast<InlineAsm>(CS.getCalledValue())) {
+          unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
+          std::vector<TargetLowering::AsmOperandInfo> Ops =
+            TLI->ParseConstraints(CS);
+          for (size_t I = 0, E = Ops.size(); I != E; ++I) {
+            TargetLowering::AsmOperandInfo &Op = Ops[I];
+            if (Op.Type == InlineAsm::isClobber) {
+              // Clobbers don't have SDValue operands, hence SDValue().
+              TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
+              std::pair<unsigned, const TargetRegisterClass*> PhysReg =
+                TLI->getRegForInlineAsmConstraint(Op.ConstraintCode,
+                                                  Op.ConstraintVT);
+              if (PhysReg.first == SP)
+                MF->getFrameInfo()->setHasInlineAsmWithSPAdjust(true);
+            }
+          }
+        }
+      }
+
       // Mark values used outside their block as exported, by allocating
       // a virtual register for them.
       if (isUsedOutsideOfDefiningBlock(I))

Modified: head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
==============================================================================
--- head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -851,12 +851,20 @@ void RegsForValue::AddInlineAsmOperands(
   SDValue Res = DAG.getTargetConstant(Flag, MVT::i32);
   Ops.push_back(Res);
 
+  unsigned SP = TLI.getStackPointerRegisterToSaveRestore();
   for (unsigned Value = 0, Reg = 0, e = ValueVTs.size(); Value != e; ++Value) {
     unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(), ValueVTs[Value]);
     MVT RegisterVT = RegVTs[Value];
     for (unsigned i = 0; i != NumRegs; ++i) {
       assert(Reg < Regs.size() && "Mismatch in # registers expected");
-      Ops.push_back(DAG.getRegister(Regs[Reg++], RegisterVT));
+      unsigned TheReg = Regs[Reg++];
+      Ops.push_back(DAG.getRegister(TheReg, RegisterVT));
+
+      if (TheReg == SP && Code == InlineAsm::Kind_Clobber) {
+        // If we clobbered the stack pointer, MFI should know about it.
+        assert(DAG.getMachineFunction().getFrameInfo()->
+            hasInlineAsmWithSPAdjust());
+      }
     }
   }
 }
@@ -3370,9 +3378,7 @@ void SelectionDAGBuilder::visitAlloca(co
   setValue(&I, DSA);
   DAG.setRoot(DSA.getValue(1));
 
-  // Inform the Frame Information that we have just allocated a variable-sized
-  // object.
-  FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1);
+  assert(FuncInfo.MF->getFrameInfo()->hasVarSizedObjects());
 }
 
 void SelectionDAGBuilder::visitLoad(const LoadInst &I) {

Modified: head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
==============================================================================
--- head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -419,7 +419,7 @@ bool SelectionDAGISel::runOnMachineFunct
   SplitCriticalSideEffectEdges(const_cast<Function&>(Fn), this);
 
   CurDAG->init(*MF, TTI, TLI);
-  FuncInfo->set(Fn, *MF);
+  FuncInfo->set(Fn, *MF, CurDAG);
 
   if (UseMBPI && OptLevel != CodeGenOpt::None)
     FuncInfo->BPI = &getAnalysis<BranchProbabilityInfo>();
@@ -428,7 +428,8 @@ bool SelectionDAGISel::runOnMachineFunct
 
   SDB->init(GFI, *AA, LibInfo);
 
-  MF->setHasMSInlineAsm(false);
+  MF->setHasInlineAsm(false);
+
   SelectAllBasicBlocks(Fn);
 
   // If the first basic block in the function has live ins that need to be
@@ -511,7 +512,7 @@ bool SelectionDAGISel::runOnMachineFunct
   for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
        ++I) {
 
-    if (MFI->hasCalls() && MF->hasMSInlineAsm())
+    if (MFI->hasCalls() && MF->hasInlineAsm())
       break;
 
     const MachineBasicBlock *MBB = I;
@@ -522,8 +523,8 @@ bool SelectionDAGISel::runOnMachineFunct
           II->isStackAligningInlineAsm()) {
         MFI->setHasCalls(true);
       }
-      if (II->isMSInlineAsm()) {
-        MF->setHasMSInlineAsm(true);
+      if (II->isInlineAsm()) {
+        MF->setHasInlineAsm(true);
       }
     }
   }

Modified: head/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
==============================================================================
--- head/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -4192,6 +4192,11 @@ bool AsmParser::parseMSInlineAsm(
         AsmStrRewrites.push_back(AsmRewrite(AOK_Input, Start, SymName.size()));
       }
     }
+
+    // Consider implicit defs to be clobbers.  Think of cpuid and push.
+    const uint16_t *ImpDefs = Desc.getImplicitDefs();
+    for (unsigned I = 0, E = Desc.getNumImplicitDefs(); I != E; ++I)
+      ClobberRegs.push_back(ImpDefs[I]);
   }
 
   // Set the number of Outputs and Inputs.

Modified: head/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
==============================================================================
--- head/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -50,7 +50,7 @@ bool X86FrameLowering::hasFP(const Machi
   return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
           RegInfo->needsStackRealignment(MF) ||
           MFI->hasVarSizedObjects() ||
-          MFI->isFrameAddressTaken() || MF.hasMSInlineAsm() ||
+          MFI->isFrameAddressTaken() || MFI->hasInlineAsmWithSPAdjust() ||
           MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
           MMI.callsUnwindInit() || MMI.callsEHReturn());
 }

Modified: head/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
==============================================================================
--- head/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Tue Mar 18 18:10:35 2014	(r263311)
+++ head/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Tue Mar 18 19:23:41 2014	(r263312)
@@ -403,18 +403,15 @@ bool X86RegisterInfo::hasBasePointer(con
    if (!EnableBasePointer)
      return false;
 
-   // When we need stack realignment and there are dynamic allocas, we can't
-   // reference off of the stack pointer, so we reserve a base pointer.
-   //
-   // This is also true if the function contain MS-style inline assembly.  We
-   // do this because if any stack changes occur in the inline assembly, e.g.,
-   // "pusha", then any C local variable or C argument references in the
-   // inline assembly will be wrong because the SP is not properly tracked.
-   if ((needsStackRealignment(MF) && MFI->hasVarSizedObjects()) ||
-       MF.hasMSInlineAsm())
-     return true;
-
-   return false;
+   // When we need stack realignment, we can't address the stack from the frame
+   // pointer.  When we have dynamic allocas or stack-adjusting inline asm, we
+   // can't address variables from the stack pointer.  MS inline asm can
+   // reference locals while also adjusting the stack pointer.  When we can't
+   // use both the SP and the FP, we need a separate base pointer register.
+   bool CantUseFP = needsStackRealignment(MF);
+   bool CantUseSP =
+       MFI->hasVarSizedObjects() || MFI->hasInlineAsmWithSPAdjust();
+   return CantUseFP && CantUseSP;
 }
 
 bool X86RegisterInfo::canRealignStack(const MachineFunction &MF) const {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 14 dfilter service freebsd_committer 2014-03-26 07:42:49 UTC
Author: dim
Date: Wed Mar 26 07:42:43 2014
New Revision: 263765
URL: http://svnweb.freebsd.org/changeset/base/263765

Log:
  MFC r263312:
  
  Pull in r196939 from upstream llvm trunk (by Reid Kleckner):
  
    Reland "Fix miscompile of MS inline assembly with stack realignment"
  
    This re-lands commit r196876, which was reverted in r196879.
  
    The tests have been fixed to pass on platforms with a stack alignment
    larger than 4.
  
    Update to clang side tests will land shortly.
  
  Pull in r196986 from upstream llvm trunk (by Reid Kleckner):
  
    Revert the backend fatal error from r196939
  
    The combination of inline asm, stack realignment, and dynamic allocas
    turns out to be too common to reject out of hand.
  
    ASan inserts empy inline asm fragments and uses aligned allocas.
    Compiling any trivial function containing a dynamic alloca with ASan is
    enough to trigger the check.
  
    XFAIL the test cases that would be miscompiled and add one that uses the
    relevant functionality.
  
  Pull in r202930 from upstream llvm trunk (by Hans Wennborg):
  
    Check for dynamic allocas and inline asm that clobbers sp before building
    selection dag (PR19012)
  
    In X86SelectionDagInfo::EmitTargetCodeForMemcpy we check with MachineFrameInfo
    to make sure that ESI isn't used as a base pointer register before we choose to
    emit rep movs (which clobbers esi).
  
    The problem is that MachineFrameInfo wouldn't know about dynamic allocas or
    inline asm that clobbers the stack pointer until SelectionDAGBuilder has
    encountered them.
  
    This patch fixes the problem by checking for such things when building the
    FunctionLoweringInfo.
  
    Differential Revision: http://llvm-reviews.chandlerc.com/D2954
  
  Together, these commits fix the problem encountered in the devel/emacs
  port on the i386 architecture, where a combination of stack realignment,
  alloca() and memcpy() could incidentally clobber the %esi register,
  leading to segfaults in the temacs build-time utility.
  
  See also: http://llvm.org/PR18171 and http://llvm.org/PR19012
  
  Reported by:	ashish
  PR:		ports/183064
  
  MFC r263313:
  
  Pull in r203311 from upstream llvm trunk (by Arnold Schwaighofer):
  
    ISel: Make VSELECT selection terminate in cases where the condition type has to
    be split and the result type widened.
  
    When the condition of a vselect has to be split it makes no sense widening the
    vselect and thereby widening the condition. We end up in an endless loop of
    widening (vselect result type) and splitting (condition mask type) doing this.
    Instead, split both the condition and the vselect and widen the result.
  
    I ran this over the test suite with i686 and mattr=+sse and saw no regressions.
  
    Fixes PR18036.
  
  With this fix the original problem case from the graphics/rawtherapee
  port (posted in http://llvm.org/PR18036 ) now compiles within ~97MB RSS.
  
  Reported by:	mandree
  
  MFC r263320:
  
  Add separate patch files for all the customizations we have currently
  applied to our copy of llvm/clang.  These can be applied in alphabetical
  order to a pristine llvm/clang 3.4 release source tree, to result in the
  same version used in FreeBSD.
  
  This is intended to clearly document all the changes until now, which
  mostly consist of cherry pickings from the respective upstream trunks,
  plus a number of hand-written FreeBSD-specific ones.  Hopefully those
  can eventually be cleaned up and sent upstream too.

Added:
  stable/9/contrib/llvm/patches/
     - copied from r263320, head/contrib/llvm/patches/
Modified:
  stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
  stable/9/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
  stable/9/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
  stable/9/contrib/llvm/lib/CodeGen/MachineFunction.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  stable/9/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
  stable/9/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
  stable/9/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
Directory Properties:
  stable/9/   (props changed)
  stable/9/contrib/   (props changed)
  stable/9/contrib/llvm/   (props changed)

Changes in other areas also in this revision:
Added:
  stable/10/contrib/llvm/patches/
     - copied from r263320, head/contrib/llvm/patches/
Modified:
  stable/10/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
  stable/10/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
  stable/10/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
  stable/10/contrib/llvm/lib/CodeGen/MachineFunction.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  stable/10/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
  stable/10/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
  stable/10/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
Directory Properties:
  stable/10/   (props changed)

Modified: stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
==============================================================================
--- stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -41,6 +41,7 @@ class MachineBasicBlock;
 class MachineFunction;
 class MachineModuleInfo;
 class MachineRegisterInfo;
+class SelectionDAG;
 class TargetLowering;
 class Value;
 
@@ -125,7 +126,7 @@ public:
   /// set - Initialize this FunctionLoweringInfo with the given Function
   /// and its associated MachineFunction.
   ///
-  void set(const Function &Fn, MachineFunction &MF);
+  void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG);
 
   /// clear - Clear out all the function-specific state. This returns this
   /// FunctionLoweringInfo to an empty state, ready to be used for a

Modified: stable/9/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
==============================================================================
--- stable/9/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -223,6 +223,10 @@ class MachineFrameInfo {
   /// Whether the "realign-stack" option is on.
   bool RealignOption;
 
+  /// True if the function includes inline assembly that adjusts the stack
+  /// pointer.
+  bool HasInlineAsmWithSPAdjust;
+
   const TargetFrameLowering *getFrameLowering() const;
 public:
     explicit MachineFrameInfo(const TargetMachine &TM, bool RealignOpt)
@@ -240,6 +244,7 @@ public:
     LocalFrameSize = 0;
     LocalFrameMaxAlign = 0;
     UseLocalStackAllocationBlock = false;
+    HasInlineAsmWithSPAdjust = false;
   }
 
   /// hasStackObjects - Return true if there are any stack objects in this
@@ -451,6 +456,10 @@ public:
   bool hasCalls() const { return HasCalls; }
   void setHasCalls(bool V) { HasCalls = V; }
 
+  /// Returns true if the function contains any stack-adjusting inline assembly.
+  bool hasInlineAsmWithSPAdjust() const { return HasInlineAsmWithSPAdjust; }
+  void setHasInlineAsmWithSPAdjust(bool B) { HasInlineAsmWithSPAdjust = B; }
+
   /// getMaxCallFrameSize - Return the maximum size of a call frame that must be
   /// allocated for an outgoing function call.  This is only available if
   /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
@@ -521,7 +530,7 @@ public:
   /// variable sized object is created, whether or not the index returned is
   /// actually used.
   ///
-  int CreateVariableSizedObject(unsigned Alignment);
+  int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
 
   /// getCalleeSavedInfo - Returns a reference to call saved info vector for the
   /// current function.

Modified: stable/9/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
==============================================================================
--- stable/9/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -131,8 +131,8 @@ class MachineFunction {
   /// about the control flow of such functions.
   bool ExposesReturnsTwice;
 
-  /// True if the function includes MS-style inline assembly.
-  bool HasMSInlineAsm;
+  /// True if the function includes any inline assembly.
+  bool HasInlineAsm;
 
   MachineFunction(const MachineFunction &) LLVM_DELETED_FUNCTION;
   void operator=(const MachineFunction&) LLVM_DELETED_FUNCTION;
@@ -218,15 +218,14 @@ public:
     ExposesReturnsTwice = B;
   }
 
-  /// Returns true if the function contains any MS-style inline assembly.
-  bool hasMSInlineAsm() const {
-    return HasMSInlineAsm;
+  /// Returns true if the function contains any inline assembly.
+  bool hasInlineAsm() const {
+    return HasInlineAsm;
   }
 
-  /// Set a flag that indicates that the function contains MS-style inline
-  /// assembly.
-  void setHasMSInlineAsm(bool B) {
-    HasMSInlineAsm = B;
+  /// Set a flag that indicates that the function contains inline assembly.
+  void setHasInlineAsm(bool B) {
+    HasInlineAsm = B;
   }
   
   /// getInfo - Keep track of various per-function pieces of information for

Modified: stable/9/contrib/llvm/lib/CodeGen/MachineFunction.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -525,13 +525,14 @@ int MachineFrameInfo::CreateSpillStackOb
 /// variable sized object is created, whether or not the index returned is
 /// actually used.
 ///
-int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment) {
+int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment,
+                                                const AllocaInst *Alloca) {
   HasVarSizedObjects = true;
   Alignment =
     clampStackAlignment(!getFrameLowering()->isStackRealignable() ||
                           !RealignOption,
                         Alignment, getFrameLowering()->getStackAlignment()); 
-  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, 0));
+  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, Alloca));
   ensureMaxAlignment(Alignment);
   return (int)Objects.size()-NumFixedObjects-1;
 }

Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -33,6 +33,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetFrameLowering.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -55,7 +56,8 @@ static bool isUsedOutsideOfDefiningBlock
   return false;
 }
 
-void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
+void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
+                               SelectionDAG *DAG) {
   const TargetLowering *TLI = TM.getTargetLowering();
 
   Fn = &fn;
@@ -100,6 +102,43 @@ void FunctionLoweringInfo::set(const Fun
   for (; BB != EB; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
+      // Look for dynamic allocas.
+      if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
+        if (!AI->isStaticAlloca()) {
+          unsigned Align = std::max(
+              (unsigned)TLI->getDataLayout()->getPrefTypeAlignment(
+                AI->getAllocatedType()),
+              AI->getAlignment());
+          unsigned StackAlign = TM.getFrameLowering()->getStackAlignment();
+          if (Align <= StackAlign)
+            Align = 0;
+          // Inform the Frame Information that we have variable-sized objects.
+          MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, AI);
+        }
+      }
+
+      // Look for inline asm that clobbers the SP register.
+      if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
+        ImmutableCallSite CS(I);
+        if (const InlineAsm *IA = dyn_cast<InlineAsm>(CS.getCalledValue())) {
+          unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
+          std::vector<TargetLowering::AsmOperandInfo> Ops =
+            TLI->ParseConstraints(CS);
+          for (size_t I = 0, E = Ops.size(); I != E; ++I) {
+            TargetLowering::AsmOperandInfo &Op = Ops[I];
+            if (Op.Type == InlineAsm::isClobber) {
+              // Clobbers don't have SDValue operands, hence SDValue().
+              TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
+              std::pair<unsigned, const TargetRegisterClass*> PhysReg =
+                TLI->getRegForInlineAsmConstraint(Op.ConstraintCode,
+                                                  Op.ConstraintVT);
+              if (PhysReg.first == SP)
+                MF->getFrameInfo()->setHasInlineAsmWithSPAdjust(true);
+            }
+          }
+        }
+      }
+
       // Mark values used outside their block as exported, by allocating
       // a virtual register for them.
       if (isUsedOutsideOfDefiningBlock(I))

Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -2180,6 +2180,17 @@ SDValue DAGTypeLegalizer::WidenVecRes_SE
     if (getTypeAction(CondVT) == TargetLowering::TypeWidenVector)
       Cond1 = GetWidenedVector(Cond1);
 
+    // If we have to split the condition there is no point in widening the
+    // select. This would result in an cycle of widening the select ->
+    // widening the condition operand -> splitting the condition operand ->
+    // splitting the select -> widening the select. Instead split this select
+    // further and widen the resulting type.
+    if (getTypeAction(CondVT) == TargetLowering::TypeSplitVector) {
+      SDValue SplitSelect = SplitVecOp_VSELECT(N, 0);
+      SDValue Res = ModifyToType(SplitSelect, WidenVT);
+      return Res;
+    }
+
     if (Cond1.getValueType() != CondWidenVT)
       Cond1 = ModifyToType(Cond1, CondWidenVT);
   }

Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -851,12 +851,20 @@ void RegsForValue::AddInlineAsmOperands(
   SDValue Res = DAG.getTargetConstant(Flag, MVT::i32);
   Ops.push_back(Res);
 
+  unsigned SP = TLI.getStackPointerRegisterToSaveRestore();
   for (unsigned Value = 0, Reg = 0, e = ValueVTs.size(); Value != e; ++Value) {
     unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(), ValueVTs[Value]);
     MVT RegisterVT = RegVTs[Value];
     for (unsigned i = 0; i != NumRegs; ++i) {
       assert(Reg < Regs.size() && "Mismatch in # registers expected");
-      Ops.push_back(DAG.getRegister(Regs[Reg++], RegisterVT));
+      unsigned TheReg = Regs[Reg++];
+      Ops.push_back(DAG.getRegister(TheReg, RegisterVT));
+
+      if (TheReg == SP && Code == InlineAsm::Kind_Clobber) {
+        // If we clobbered the stack pointer, MFI should know about it.
+        assert(DAG.getMachineFunction().getFrameInfo()->
+            hasInlineAsmWithSPAdjust());
+      }
     }
   }
 }
@@ -3370,9 +3378,7 @@ void SelectionDAGBuilder::visitAlloca(co
   setValue(&I, DSA);
   DAG.setRoot(DSA.getValue(1));
 
-  // Inform the Frame Information that we have just allocated a variable-sized
-  // object.
-  FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1);
+  assert(FuncInfo.MF->getFrameInfo()->hasVarSizedObjects());
 }
 
 void SelectionDAGBuilder::visitLoad(const LoadInst &I) {

Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -419,7 +419,7 @@ bool SelectionDAGISel::runOnMachineFunct
   SplitCriticalSideEffectEdges(const_cast<Function&>(Fn), this);
 
   CurDAG->init(*MF, TTI, TLI);
-  FuncInfo->set(Fn, *MF);
+  FuncInfo->set(Fn, *MF, CurDAG);
 
   if (UseMBPI && OptLevel != CodeGenOpt::None)
     FuncInfo->BPI = &getAnalysis<BranchProbabilityInfo>();
@@ -428,7 +428,8 @@ bool SelectionDAGISel::runOnMachineFunct
 
   SDB->init(GFI, *AA, LibInfo);
 
-  MF->setHasMSInlineAsm(false);
+  MF->setHasInlineAsm(false);
+
   SelectAllBasicBlocks(Fn);
 
   // If the first basic block in the function has live ins that need to be
@@ -511,7 +512,7 @@ bool SelectionDAGISel::runOnMachineFunct
   for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
        ++I) {
 
-    if (MFI->hasCalls() && MF->hasMSInlineAsm())
+    if (MFI->hasCalls() && MF->hasInlineAsm())
       break;
 
     const MachineBasicBlock *MBB = I;
@@ -522,8 +523,8 @@ bool SelectionDAGISel::runOnMachineFunct
           II->isStackAligningInlineAsm()) {
         MFI->setHasCalls(true);
       }
-      if (II->isMSInlineAsm()) {
-        MF->setHasMSInlineAsm(true);
+      if (II->isInlineAsm()) {
+        MF->setHasInlineAsm(true);
       }
     }
   }

Modified: stable/9/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -4192,6 +4192,11 @@ bool AsmParser::parseMSInlineAsm(
         AsmStrRewrites.push_back(AsmRewrite(AOK_Input, Start, SymName.size()));
       }
     }
+
+    // Consider implicit defs to be clobbers.  Think of cpuid and push.
+    const uint16_t *ImpDefs = Desc.getImplicitDefs();
+    for (unsigned I = 0, E = Desc.getNumImplicitDefs(); I != E; ++I)
+      ClobberRegs.push_back(ImpDefs[I]);
   }
 
   // Set the number of Outputs and Inputs.

Modified: stable/9/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -50,7 +50,7 @@ bool X86FrameLowering::hasFP(const Machi
   return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
           RegInfo->needsStackRealignment(MF) ||
           MFI->hasVarSizedObjects() ||
-          MFI->isFrameAddressTaken() || MF.hasMSInlineAsm() ||
+          MFI->isFrameAddressTaken() || MFI->hasInlineAsmWithSPAdjust() ||
           MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
           MMI.callsUnwindInit() || MMI.callsEHReturn());
 }

Modified: stable/9/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
==============================================================================
--- stable/9/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/9/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -403,18 +403,15 @@ bool X86RegisterInfo::hasBasePointer(con
    if (!EnableBasePointer)
      return false;
 
-   // When we need stack realignment and there are dynamic allocas, we can't
-   // reference off of the stack pointer, so we reserve a base pointer.
-   //
-   // This is also true if the function contain MS-style inline assembly.  We
-   // do this because if any stack changes occur in the inline assembly, e.g.,
-   // "pusha", then any C local variable or C argument references in the
-   // inline assembly will be wrong because the SP is not properly tracked.
-   if ((needsStackRealignment(MF) && MFI->hasVarSizedObjects()) ||
-       MF.hasMSInlineAsm())
-     return true;
-
-   return false;
+   // When we need stack realignment, we can't address the stack from the frame
+   // pointer.  When we have dynamic allocas or stack-adjusting inline asm, we
+   // can't address variables from the stack pointer.  MS inline asm can
+   // reference locals while also adjusting the stack pointer.  When we can't
+   // use both the SP and the FP, we need a separate base pointer register.
+   bool CantUseFP = needsStackRealignment(MF);
+   bool CantUseSP =
+       MFI->hasVarSizedObjects() || MFI->hasInlineAsmWithSPAdjust();
+   return CantUseFP && CantUseSP;
 }
 
 bool X86RegisterInfo::canRealignStack(const MachineFunction &MF) const {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 15 dfilter service freebsd_committer 2014-03-26 07:42:53 UTC
Author: dim
Date: Wed Mar 26 07:42:43 2014
New Revision: 263765
URL: http://svnweb.freebsd.org/changeset/base/263765

Log:
  MFC r263312:
  
  Pull in r196939 from upstream llvm trunk (by Reid Kleckner):
  
    Reland "Fix miscompile of MS inline assembly with stack realignment"
  
    This re-lands commit r196876, which was reverted in r196879.
  
    The tests have been fixed to pass on platforms with a stack alignment
    larger than 4.
  
    Update to clang side tests will land shortly.
  
  Pull in r196986 from upstream llvm trunk (by Reid Kleckner):
  
    Revert the backend fatal error from r196939
  
    The combination of inline asm, stack realignment, and dynamic allocas
    turns out to be too common to reject out of hand.
  
    ASan inserts empy inline asm fragments and uses aligned allocas.
    Compiling any trivial function containing a dynamic alloca with ASan is
    enough to trigger the check.
  
    XFAIL the test cases that would be miscompiled and add one that uses the
    relevant functionality.
  
  Pull in r202930 from upstream llvm trunk (by Hans Wennborg):
  
    Check for dynamic allocas and inline asm that clobbers sp before building
    selection dag (PR19012)
  
    In X86SelectionDagInfo::EmitTargetCodeForMemcpy we check with MachineFrameInfo
    to make sure that ESI isn't used as a base pointer register before we choose to
    emit rep movs (which clobbers esi).
  
    The problem is that MachineFrameInfo wouldn't know about dynamic allocas or
    inline asm that clobbers the stack pointer until SelectionDAGBuilder has
    encountered them.
  
    This patch fixes the problem by checking for such things when building the
    FunctionLoweringInfo.
  
    Differential Revision: http://llvm-reviews.chandlerc.com/D2954
  
  Together, these commits fix the problem encountered in the devel/emacs
  port on the i386 architecture, where a combination of stack realignment,
  alloca() and memcpy() could incidentally clobber the %esi register,
  leading to segfaults in the temacs build-time utility.
  
  See also: http://llvm.org/PR18171 and http://llvm.org/PR19012
  
  Reported by:	ashish
  PR:		ports/183064
  
  MFC r263313:
  
  Pull in r203311 from upstream llvm trunk (by Arnold Schwaighofer):
  
    ISel: Make VSELECT selection terminate in cases where the condition type has to
    be split and the result type widened.
  
    When the condition of a vselect has to be split it makes no sense widening the
    vselect and thereby widening the condition. We end up in an endless loop of
    widening (vselect result type) and splitting (condition mask type) doing this.
    Instead, split both the condition and the vselect and widen the result.
  
    I ran this over the test suite with i686 and mattr=+sse and saw no regressions.
  
    Fixes PR18036.
  
  With this fix the original problem case from the graphics/rawtherapee
  port (posted in http://llvm.org/PR18036 ) now compiles within ~97MB RSS.
  
  Reported by:	mandree
  
  MFC r263320:
  
  Add separate patch files for all the customizations we have currently
  applied to our copy of llvm/clang.  These can be applied in alphabetical
  order to a pristine llvm/clang 3.4 release source tree, to result in the
  same version used in FreeBSD.
  
  This is intended to clearly document all the changes until now, which
  mostly consist of cherry pickings from the respective upstream trunks,
  plus a number of hand-written FreeBSD-specific ones.  Hopefully those
  can eventually be cleaned up and sent upstream too.

Added:
  stable/10/contrib/llvm/patches/
     - copied from r263320, head/contrib/llvm/patches/
Modified:
  stable/10/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
  stable/10/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
  stable/10/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
  stable/10/contrib/llvm/lib/CodeGen/MachineFunction.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  stable/10/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
  stable/10/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
  stable/10/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Added:
  stable/9/contrib/llvm/patches/
     - copied from r263320, head/contrib/llvm/patches/
Modified:
  stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
  stable/9/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
  stable/9/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
  stable/9/contrib/llvm/lib/CodeGen/MachineFunction.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  stable/9/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
  stable/9/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
  stable/9/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
Directory Properties:
  stable/9/   (props changed)
  stable/9/contrib/   (props changed)
  stable/9/contrib/llvm/   (props changed)

Modified: stable/10/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
==============================================================================
--- stable/10/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -41,6 +41,7 @@ class MachineBasicBlock;
 class MachineFunction;
 class MachineModuleInfo;
 class MachineRegisterInfo;
+class SelectionDAG;
 class TargetLowering;
 class Value;
 
@@ -125,7 +126,7 @@ public:
   /// set - Initialize this FunctionLoweringInfo with the given Function
   /// and its associated MachineFunction.
   ///
-  void set(const Function &Fn, MachineFunction &MF);
+  void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG);
 
   /// clear - Clear out all the function-specific state. This returns this
   /// FunctionLoweringInfo to an empty state, ready to be used for a

Modified: stable/10/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h
==============================================================================
--- stable/10/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/include/llvm/CodeGen/MachineFrameInfo.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -223,6 +223,10 @@ class MachineFrameInfo {
   /// Whether the "realign-stack" option is on.
   bool RealignOption;
 
+  /// True if the function includes inline assembly that adjusts the stack
+  /// pointer.
+  bool HasInlineAsmWithSPAdjust;
+
   const TargetFrameLowering *getFrameLowering() const;
 public:
     explicit MachineFrameInfo(const TargetMachine &TM, bool RealignOpt)
@@ -240,6 +244,7 @@ public:
     LocalFrameSize = 0;
     LocalFrameMaxAlign = 0;
     UseLocalStackAllocationBlock = false;
+    HasInlineAsmWithSPAdjust = false;
   }
 
   /// hasStackObjects - Return true if there are any stack objects in this
@@ -451,6 +456,10 @@ public:
   bool hasCalls() const { return HasCalls; }
   void setHasCalls(bool V) { HasCalls = V; }
 
+  /// Returns true if the function contains any stack-adjusting inline assembly.
+  bool hasInlineAsmWithSPAdjust() const { return HasInlineAsmWithSPAdjust; }
+  void setHasInlineAsmWithSPAdjust(bool B) { HasInlineAsmWithSPAdjust = B; }
+
   /// getMaxCallFrameSize - Return the maximum size of a call frame that must be
   /// allocated for an outgoing function call.  This is only available if
   /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
@@ -521,7 +530,7 @@ public:
   /// variable sized object is created, whether or not the index returned is
   /// actually used.
   ///
-  int CreateVariableSizedObject(unsigned Alignment);
+  int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
 
   /// getCalleeSavedInfo - Returns a reference to call saved info vector for the
   /// current function.

Modified: stable/10/contrib/llvm/include/llvm/CodeGen/MachineFunction.h
==============================================================================
--- stable/10/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/include/llvm/CodeGen/MachineFunction.h	Wed Mar 26 07:42:43 2014	(r263765)
@@ -131,8 +131,8 @@ class MachineFunction {
   /// about the control flow of such functions.
   bool ExposesReturnsTwice;
 
-  /// True if the function includes MS-style inline assembly.
-  bool HasMSInlineAsm;
+  /// True if the function includes any inline assembly.
+  bool HasInlineAsm;
 
   MachineFunction(const MachineFunction &) LLVM_DELETED_FUNCTION;
   void operator=(const MachineFunction&) LLVM_DELETED_FUNCTION;
@@ -218,15 +218,14 @@ public:
     ExposesReturnsTwice = B;
   }
 
-  /// Returns true if the function contains any MS-style inline assembly.
-  bool hasMSInlineAsm() const {
-    return HasMSInlineAsm;
+  /// Returns true if the function contains any inline assembly.
+  bool hasInlineAsm() const {
+    return HasInlineAsm;
   }
 
-  /// Set a flag that indicates that the function contains MS-style inline
-  /// assembly.
-  void setHasMSInlineAsm(bool B) {
-    HasMSInlineAsm = B;
+  /// Set a flag that indicates that the function contains inline assembly.
+  void setHasInlineAsm(bool B) {
+    HasInlineAsm = B;
   }
   
   /// getInfo - Keep track of various per-function pieces of information for

Modified: stable/10/contrib/llvm/lib/CodeGen/MachineFunction.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/CodeGen/MachineFunction.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -525,13 +525,14 @@ int MachineFrameInfo::CreateSpillStackOb
 /// variable sized object is created, whether or not the index returned is
 /// actually used.
 ///
-int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment) {
+int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment,
+                                                const AllocaInst *Alloca) {
   HasVarSizedObjects = true;
   Alignment =
     clampStackAlignment(!getFrameLowering()->isStackRealignable() ||
                           !RealignOption,
                         Alignment, getFrameLowering()->getStackAlignment()); 
-  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, 0));
+  Objects.push_back(StackObject(0, Alignment, 0, false, false, true, Alloca));
   ensureMaxAlignment(Alignment);
   return (int)Objects.size()-NumFixedObjects-1;
 }

Modified: stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -33,6 +33,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetFrameLowering.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -55,7 +56,8 @@ static bool isUsedOutsideOfDefiningBlock
   return false;
 }
 
-void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
+void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
+                               SelectionDAG *DAG) {
   const TargetLowering *TLI = TM.getTargetLowering();
 
   Fn = &fn;
@@ -100,6 +102,43 @@ void FunctionLoweringInfo::set(const Fun
   for (; BB != EB; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
+      // Look for dynamic allocas.
+      if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
+        if (!AI->isStaticAlloca()) {
+          unsigned Align = std::max(
+              (unsigned)TLI->getDataLayout()->getPrefTypeAlignment(
+                AI->getAllocatedType()),
+              AI->getAlignment());
+          unsigned StackAlign = TM.getFrameLowering()->getStackAlignment();
+          if (Align <= StackAlign)
+            Align = 0;
+          // Inform the Frame Information that we have variable-sized objects.
+          MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, AI);
+        }
+      }
+
+      // Look for inline asm that clobbers the SP register.
+      if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
+        ImmutableCallSite CS(I);
+        if (const InlineAsm *IA = dyn_cast<InlineAsm>(CS.getCalledValue())) {
+          unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
+          std::vector<TargetLowering::AsmOperandInfo> Ops =
+            TLI->ParseConstraints(CS);
+          for (size_t I = 0, E = Ops.size(); I != E; ++I) {
+            TargetLowering::AsmOperandInfo &Op = Ops[I];
+            if (Op.Type == InlineAsm::isClobber) {
+              // Clobbers don't have SDValue operands, hence SDValue().
+              TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
+              std::pair<unsigned, const TargetRegisterClass*> PhysReg =
+                TLI->getRegForInlineAsmConstraint(Op.ConstraintCode,
+                                                  Op.ConstraintVT);
+              if (PhysReg.first == SP)
+                MF->getFrameInfo()->setHasInlineAsmWithSPAdjust(true);
+            }
+          }
+        }
+      }
+
       // Mark values used outside their block as exported, by allocating
       // a virtual register for them.
       if (isUsedOutsideOfDefiningBlock(I))

Modified: stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -2180,6 +2180,17 @@ SDValue DAGTypeLegalizer::WidenVecRes_SE
     if (getTypeAction(CondVT) == TargetLowering::TypeWidenVector)
       Cond1 = GetWidenedVector(Cond1);
 
+    // If we have to split the condition there is no point in widening the
+    // select. This would result in an cycle of widening the select ->
+    // widening the condition operand -> splitting the condition operand ->
+    // splitting the select -> widening the select. Instead split this select
+    // further and widen the resulting type.
+    if (getTypeAction(CondVT) == TargetLowering::TypeSplitVector) {
+      SDValue SplitSelect = SplitVecOp_VSELECT(N, 0);
+      SDValue Res = ModifyToType(SplitSelect, WidenVT);
+      return Res;
+    }
+
     if (Cond1.getValueType() != CondWidenVT)
       Cond1 = ModifyToType(Cond1, CondWidenVT);
   }

Modified: stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -851,12 +851,20 @@ void RegsForValue::AddInlineAsmOperands(
   SDValue Res = DAG.getTargetConstant(Flag, MVT::i32);
   Ops.push_back(Res);
 
+  unsigned SP = TLI.getStackPointerRegisterToSaveRestore();
   for (unsigned Value = 0, Reg = 0, e = ValueVTs.size(); Value != e; ++Value) {
     unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(), ValueVTs[Value]);
     MVT RegisterVT = RegVTs[Value];
     for (unsigned i = 0; i != NumRegs; ++i) {
       assert(Reg < Regs.size() && "Mismatch in # registers expected");
-      Ops.push_back(DAG.getRegister(Regs[Reg++], RegisterVT));
+      unsigned TheReg = Regs[Reg++];
+      Ops.push_back(DAG.getRegister(TheReg, RegisterVT));
+
+      if (TheReg == SP && Code == InlineAsm::Kind_Clobber) {
+        // If we clobbered the stack pointer, MFI should know about it.
+        assert(DAG.getMachineFunction().getFrameInfo()->
+            hasInlineAsmWithSPAdjust());
+      }
     }
   }
 }
@@ -3370,9 +3378,7 @@ void SelectionDAGBuilder::visitAlloca(co
   setValue(&I, DSA);
   DAG.setRoot(DSA.getValue(1));
 
-  // Inform the Frame Information that we have just allocated a variable-sized
-  // object.
-  FuncInfo.MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1);
+  assert(FuncInfo.MF->getFrameInfo()->hasVarSizedObjects());
 }
 
 void SelectionDAGBuilder::visitLoad(const LoadInst &I) {

Modified: stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -419,7 +419,7 @@ bool SelectionDAGISel::runOnMachineFunct
   SplitCriticalSideEffectEdges(const_cast<Function&>(Fn), this);
 
   CurDAG->init(*MF, TTI, TLI);
-  FuncInfo->set(Fn, *MF);
+  FuncInfo->set(Fn, *MF, CurDAG);
 
   if (UseMBPI && OptLevel != CodeGenOpt::None)
     FuncInfo->BPI = &getAnalysis<BranchProbabilityInfo>();
@@ -428,7 +428,8 @@ bool SelectionDAGISel::runOnMachineFunct
 
   SDB->init(GFI, *AA, LibInfo);
 
-  MF->setHasMSInlineAsm(false);
+  MF->setHasInlineAsm(false);
+
   SelectAllBasicBlocks(Fn);
 
   // If the first basic block in the function has live ins that need to be
@@ -511,7 +512,7 @@ bool SelectionDAGISel::runOnMachineFunct
   for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
        ++I) {
 
-    if (MFI->hasCalls() && MF->hasMSInlineAsm())
+    if (MFI->hasCalls() && MF->hasInlineAsm())
       break;
 
     const MachineBasicBlock *MBB = I;
@@ -522,8 +523,8 @@ bool SelectionDAGISel::runOnMachineFunct
           II->isStackAligningInlineAsm()) {
         MFI->setHasCalls(true);
       }
-      if (II->isMSInlineAsm()) {
-        MF->setHasMSInlineAsm(true);
+      if (II->isInlineAsm()) {
+        MF->setHasInlineAsm(true);
       }
     }
   }

Modified: stable/10/contrib/llvm/lib/MC/MCParser/AsmParser.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/MC/MCParser/AsmParser.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -4192,6 +4192,11 @@ bool AsmParser::parseMSInlineAsm(
         AsmStrRewrites.push_back(AsmRewrite(AOK_Input, Start, SymName.size()));
       }
     }
+
+    // Consider implicit defs to be clobbers.  Think of cpuid and push.
+    const uint16_t *ImpDefs = Desc.getImplicitDefs();
+    for (unsigned I = 0, E = Desc.getNumImplicitDefs(); I != E; ++I)
+      ClobberRegs.push_back(ImpDefs[I]);
   }
 
   // Set the number of Outputs and Inputs.

Modified: stable/10/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/Target/X86/X86FrameLowering.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -50,7 +50,7 @@ bool X86FrameLowering::hasFP(const Machi
   return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
           RegInfo->needsStackRealignment(MF) ||
           MFI->hasVarSizedObjects() ||
-          MFI->isFrameAddressTaken() || MF.hasMSInlineAsm() ||
+          MFI->isFrameAddressTaken() || MFI->hasInlineAsmWithSPAdjust() ||
           MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
           MMI.callsUnwindInit() || MMI.callsEHReturn());
 }

Modified: stable/10/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp
==============================================================================
--- stable/10/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Wed Mar 26 07:35:24 2014	(r263764)
+++ stable/10/contrib/llvm/lib/Target/X86/X86RegisterInfo.cpp	Wed Mar 26 07:42:43 2014	(r263765)
@@ -403,18 +403,15 @@ bool X86RegisterInfo::hasBasePointer(con
    if (!EnableBasePointer)
      return false;
 
-   // When we need stack realignment and there are dynamic allocas, we can't
-   // reference off of the stack pointer, so we reserve a base pointer.
-   //
-   // This is also true if the function contain MS-style inline assembly.  We
-   // do this because if any stack changes occur in the inline assembly, e.g.,
-   // "pusha", then any C local variable or C argument references in the
-   // inline assembly will be wrong because the SP is not properly tracked.
-   if ((needsStackRealignment(MF) && MFI->hasVarSizedObjects()) ||
-       MF.hasMSInlineAsm())
-     return true;
-
-   return false;
+   // When we need stack realignment, we can't address the stack from the frame
+   // pointer.  When we have dynamic allocas or stack-adjusting inline asm, we
+   // can't address variables from the stack pointer.  MS inline asm can
+   // reference locals while also adjusting the stack pointer.  When we can't
+   // use both the SP and the FP, we need a separate base pointer register.
+   bool CantUseFP = needsStackRealignment(MF);
+   bool CantUseSP =
+       MFI->hasVarSizedObjects() || MFI->hasInlineAsmWithSPAdjust();
+   return CantUseFP && CantUseSP;
 }
 
 bool X86RegisterInfo::canRealignStack(const MachineFunction &MF) const {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"